summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-18 00:52:42 (GMT)
committerGitHub <noreply@github.com>2024-01-18 00:52:42 (GMT)
commite2c097ebdee447ded1109f99a235e65aa3533bf8 (patch)
tree7e6efa81cfe3b6fd7e010e717e2f1990c40eeddc /Lib/subprocess.py
parent4c7e09d0129dafddba58979ced9580f856f65efa (diff)
downloadcpython-e2c097ebdee447ded1109f99a235e65aa3533bf8.zip
cpython-e2c097ebdee447ded1109f99a235e65aa3533bf8.tar.gz
cpython-e2c097ebdee447ded1109f99a235e65aa3533bf8.tar.bz2
gh-104522: Fix OSError raised when run a subprocess (#114195)
Only set filename to cwd if it was caused by failed chdir(cwd). _fork_exec() now returns "noexec:chdir" for failed chdir(cwd). Co-authored-by: Robert O'Shea <PurityLake@users.noreply.github.com>
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index d5bd9a9..20db774 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1944,16 +1944,21 @@ class Popen:
SubprocessError)
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:
+ if err_msg == "noexec:chdir":
err_msg = ""
# The error must be from chdir(cwd).
err_filename = cwd
+ elif err_msg == "noexec":
+ err_msg = ""
+ err_filename = None
else:
err_filename = orig_executable
if errno_num != 0:
err_msg = os.strerror(errno_num)
- raise child_exception_type(errno_num, err_msg, err_filename)
+ if err_filename is not None:
+ raise child_exception_type(errno_num, err_msg, err_filename)
+ else:
+ raise child_exception_type(errno_num, err_msg)
raise child_exception_type(err_msg)