summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorAnders Lorentsen <Phaqui@gmail.com>2018-01-30 07:27:28 (GMT)
committerGregory P. Smith <greg@krypto.org>2018-01-30 07:27:28 (GMT)
commitdd42cb71f2cb02f3a32f016137b12a146bc0d0e2 (patch)
treed37a2ca8d77a012cae351b5f8c6654157a706bee /Lib/subprocess.py
parent14e976e00e65bf343ba0fca016c3c9132a843daf (diff)
downloadcpython-dd42cb71f2cb02f3a32f016137b12a146bc0d0e2.zip
cpython-dd42cb71f2cb02f3a32f016137b12a146bc0d0e2.tar.gz
cpython-dd42cb71f2cb02f3a32f016137b12a146bc0d0e2.tar.bz2
bpo-31961: subprocess now accepts path-like args (GH-4329)
Allow os.PathLike args in subprocess APIs.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 93635ee..2723bc9 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1097,7 +1097,12 @@ class Popen(object):
assert not pass_fds, "pass_fds not supported on Windows."
if not isinstance(args, str):
- args = list2cmdline(args)
+ try:
+ args = os.fsdecode(args) # os.PathLike -> str
+ except TypeError: # not an os.PathLike, must be a sequence.
+ args = list(args)
+ args[0] = os.fsdecode(args[0]) # os.PathLike -> str
+ args = list2cmdline(args)
# Process startup details
if startupinfo is None:
@@ -1369,7 +1374,10 @@ class Popen(object):
if isinstance(args, (str, bytes)):
args = [args]
else:
- args = list(args)
+ try:
+ args = list(args)
+ except TypeError: # os.PathLike instead of a sequence?
+ args = [os.fsencode(args)] # os.PathLike -> [str]
if shell:
# On Android the default shell is at '/system/bin/sh'.