mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-31961: Fix support of path-like executables in subprocess. (GH-5914)
This commit is contained in:
parent
1b05aa2190
commit
9e3c452639
4 changed files with 109 additions and 6 deletions
|
@ -521,7 +521,7 @@ def list2cmdline(seq):
|
|||
# "Parsing C++ Command-Line Arguments"
|
||||
result = []
|
||||
needquote = False
|
||||
for arg in seq:
|
||||
for arg in map(os.fsdecode, seq):
|
||||
bs_buf = []
|
||||
|
||||
# Add a space to separate this argument from the others
|
||||
|
@ -1203,9 +1203,23 @@ class Popen(object):
|
|||
|
||||
assert not pass_fds, "pass_fds not supported on Windows."
|
||||
|
||||
if not isinstance(args, str):
|
||||
if isinstance(args, str):
|
||||
pass
|
||||
elif isinstance(args, bytes):
|
||||
if shell:
|
||||
raise TypeError('bytes args is not allowed on Windows')
|
||||
args = list2cmdline([args])
|
||||
elif isinstance(args, os.PathLike):
|
||||
if shell:
|
||||
raise TypeError('path-like args is not allowed when '
|
||||
'shell is true')
|
||||
args = list2cmdline([args])
|
||||
else:
|
||||
args = list2cmdline(args)
|
||||
|
||||
if executable is not None:
|
||||
executable = os.fsdecode(executable)
|
||||
|
||||
# Process startup details
|
||||
if startupinfo is None:
|
||||
startupinfo = STARTUPINFO()
|
||||
|
@ -1262,7 +1276,7 @@ class Popen(object):
|
|||
int(not close_fds),
|
||||
creationflags,
|
||||
env,
|
||||
os.fspath(cwd) if cwd is not None else None,
|
||||
os.fsdecode(cwd) if cwd is not None else None,
|
||||
startupinfo)
|
||||
finally:
|
||||
# Child is launched. Close the parent's copy of those pipe
|
||||
|
@ -1510,6 +1524,11 @@ class Popen(object):
|
|||
|
||||
if isinstance(args, (str, bytes)):
|
||||
args = [args]
|
||||
elif isinstance(args, os.PathLike):
|
||||
if shell:
|
||||
raise TypeError('path-like args is not allowed when '
|
||||
'shell is true')
|
||||
args = [args]
|
||||
else:
|
||||
args = list(args)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue