mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
add execvpe -- mix of execvp and execve
This commit is contained in:
parent
dcce73af48
commit
030afb1d3a
1 changed files with 22 additions and 6 deletions
28
Lib/os.py
28
Lib/os.py
|
@ -55,16 +55,32 @@ def execle(file, *args):
|
||||||
def execlp(file, *args):
|
def execlp(file, *args):
|
||||||
execvp(file, args)
|
execvp(file, args)
|
||||||
|
|
||||||
_notfound = None
|
def execlpe(file, *args):
|
||||||
|
env = args[-1]
|
||||||
|
execvpe(file, args[:-1], env)
|
||||||
|
|
||||||
def execvp(file, args):
|
def execvp(file, args):
|
||||||
|
_execvpe(file, args)
|
||||||
|
|
||||||
|
def execvpe(file, args, env):
|
||||||
|
_execvpe(file, args, env)
|
||||||
|
|
||||||
|
_notfound = None
|
||||||
|
def _execvpe(file, args, env = None):
|
||||||
|
if env:
|
||||||
|
func = execve
|
||||||
|
argrest = (args, env)
|
||||||
|
else:
|
||||||
|
func = execv
|
||||||
|
argrest = (args,)
|
||||||
|
env = environ
|
||||||
global _notfound
|
global _notfound
|
||||||
head, tail = path.split(file)
|
head, tail = path.split(file)
|
||||||
if head:
|
if head:
|
||||||
execv(file, args)
|
apply(func, (file,) + argrest)
|
||||||
return
|
return
|
||||||
ENOENT = 2
|
if env.has_key('PATH'):
|
||||||
if environ.has_key('PATH'):
|
envpath = env['PATH']
|
||||||
envpath = environ['PATH']
|
|
||||||
else:
|
else:
|
||||||
envpath = defpath
|
envpath = defpath
|
||||||
import string
|
import string
|
||||||
|
@ -78,7 +94,7 @@ def execvp(file, args):
|
||||||
for dir in PATH:
|
for dir in PATH:
|
||||||
fullname = path.join(dir, file)
|
fullname = path.join(dir, file)
|
||||||
try:
|
try:
|
||||||
execv(fullname, args)
|
apply(func, (fullname,) + argrest)
|
||||||
except error, (errno, msg):
|
except error, (errno, msg):
|
||||||
if errno != arg[0]:
|
if errno != arg[0]:
|
||||||
exc, arg = error, (errno, msg)
|
exc, arg = error, (errno, msg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue