summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-09-03 16:36:17 (GMT)
committerGuido van Rossum <guido@python.org>2002-09-03 16:36:17 (GMT)
commit683c0fe41430d66e329279e164912cea62170f0a (patch)
tree6e632098bf419670dd9c03780cfcfd70f45a0827
parent17db21ffd0659ba3eb864b161cc2c4f63849e62e (diff)
downloadcpython-683c0fe41430d66e329279e164912cea62170f0a.zip
cpython-683c0fe41430d66e329279e164912cea62170f0a.tar.gz
cpython-683c0fe41430d66e329279e164912cea62170f0a.tar.bz2
Fix for SF bug 601077 by Zack Weinberg.
The new execvpe code would sometimes do the wrong thing when a non-executable file existed earlier in the path and an executable file of the same name existed later in the path. This patch restores the proper behavior (which is to execute the second file). When only a non-executable file exists, the correct error is still reported.
-rw-r--r--Lib/os.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 9df1ba3..a2daba8 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -309,7 +309,7 @@ def execvp(file, args):
_execvpe(file, args)
def execvpe(file, args, env):
- """execv(file, args, env)
+ """execvpe(file, args, env)
Execute the executable file (which is searched for along $PATH)
with argument list args and environment env , replacing the
@@ -339,14 +339,21 @@ def _execvpe(file, args, env=None):
else:
envpath = defpath
PATH = envpath.split(pathsep)
+ saved_exc = None
+ saved_tb = None
for dir in PATH:
fullname = path.join(dir, file)
try:
apply(func, (fullname,) + argrest)
- except error, (errno, msg):
- if errno != ENOENT and errno != ENOTDIR:
- raise
- raise error, (errno, msg)
+ except error, e:
+ tb = sys.exc_info()[2]
+ if (e.errno != ENOENT and e.errno != ENOTDIR
+ and saved_exc is None):
+ saved_exc = e
+ saved_tb = tb
+ if saved_exc:
+ raise error, saved_exc, saved_tb
+ raise error, e, tb
# Change environ to automatically call putenv() if it exists
try: