diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 93635ee61f7e9ff..b97eb3a77e5b398 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -502,6 +502,7 @@ def list2cmdline(seq): result = [] needquote = False for arg in seq: + arg = os.fspath(arg) bs_buf = [] # Add a space to separate this argument from the others diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 2a766d7c92ad822..5d4415ab7f5df0d 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -18,6 +18,7 @@ import threading import gc import textwrap +import pathlib from test.support import FakePath try: @@ -118,6 +119,19 @@ def test_io_unbuffered_works(self): p.stderr.close() p.wait() + def test_pathlib_executable(self): + p = subprocess.Popen([pathlib.Path(sys.executable), "-c", + "import sys; sys.exit(47)"]) + p.wait() + self.assertEqual(p.returncode, 47) + + def test_pathlib_argument(self): + path = pathlib.Path(sys.executable) + output = subprocess.check_output([path, "-c", + "import sys; sys.stdout.write(sys.argv[1])", + path]) + self.assertEqual(output, os.fspath(path).encode()) + def test_call_seq(self): # call() function with sequence argument rc = subprocess.call([sys.executable, "-c", diff --git a/Misc/NEWS.d/next/Library/2018-05-23-15-27-00.bpo-33617.dj349j.rst b/Misc/NEWS.d/next/Library/2018-05-23-15-27-00.bpo-33617.dj349j.rst new file mode 100644 index 000000000000000..c707ced6223a2ce --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-05-23-15-27-00.bpo-33617.dj349j.rst @@ -0,0 +1 @@ +Use os.fspath() on elements of sequences passed to subprocess.Popen() on Windows. \ No newline at end of file