Skip to content

Commit b6e835c

Browse files
committed
Backport:
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.
1 parent 344f425 commit b6e835c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Lib/os.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def execvp(file, args):
291291
_execvpe(file, args)
292292

293293
def execvpe(file, args, env):
294-
"""execv(file, args, env)
294+
"""execvpe(file, args, env)
295295
296296
Execute the executable file (which is searched for along $PATH)
297297
with argument list args and environment env , replacing the
@@ -321,14 +321,21 @@ def _execvpe(file, args, env=None):
321321
else:
322322
envpath = defpath
323323
PATH = envpath.split(pathsep)
324+
saved_exc = None
325+
saved_tb = None
324326
for dir in PATH:
325327
fullname = path.join(dir, file)
326328
try:
327329
apply(func, (fullname,) + argrest)
328-
except error, (errno, msg):
329-
if errno != ENOENT and errno != ENOTDIR:
330-
raise
331-
raise error, (errno, msg)
330+
except error, e:
331+
tb = sys.exc_info()[2]
332+
if (e.errno != ENOENT and e.errno != ENOTDIR
333+
and saved_exc is None):
334+
saved_exc = e
335+
saved_tb = tb
336+
if saved_exc:
337+
raise error, saved_exc, saved_tb
338+
raise error, e, tb
332339

333340
# Change environ to automatically call putenv() if it exists
334341
try:

0 commit comments

Comments
 (0)