mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fixes Issue #16114: The subprocess module no longer provides a
misleading error message stating that args[0] did not exist when either the cwd or executable keyword arguments specified a path that did not exist.
This commit is contained in:
commit
a10ddb8a55
4 changed files with 59 additions and 9 deletions
|
@ -1327,6 +1327,7 @@ class Popen(object):
|
|||
|
||||
if executable is None:
|
||||
executable = args[0]
|
||||
orig_executable = executable
|
||||
|
||||
# For transferring possible exec failure from child to parent.
|
||||
# Data format: "exception name:hex errno:description"
|
||||
|
@ -1409,10 +1410,17 @@ class Popen(object):
|
|||
err_msg = err_msg.decode(errors="surrogatepass")
|
||||
if issubclass(child_exception_type, OSError) and hex_errno:
|
||||
errno_num = int(hex_errno, 16)
|
||||
child_exec_never_called = (err_msg == "noexec")
|
||||
if child_exec_never_called:
|
||||
err_msg = ""
|
||||
if errno_num != 0:
|
||||
err_msg = os.strerror(errno_num)
|
||||
if errno_num == errno.ENOENT:
|
||||
err_msg += ': ' + repr(args[0])
|
||||
if child_exec_never_called:
|
||||
# The error must be from chdir(cwd).
|
||||
err_msg += ': ' + repr(cwd)
|
||||
else:
|
||||
err_msg += ': ' + repr(orig_executable)
|
||||
raise child_exception_type(errno_num, err_msg)
|
||||
raise child_exception_type(err_msg)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue