diff --git a/Lib/subprocess.py b/Lib/subprocess.py index c02fb525ec5..359dc96701a 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1125,7 +1125,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, restore_signals, start_new_session): """Execute program (POSIX version)""" - if isinstance(args, str): + if isinstance(args, (str, bytes)): args = [args] else: args = list(args) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 9e267ebf59e..d91a4a6987c 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1059,6 +1059,11 @@ def test_bytes_program(self): exitcode = subprocess.call([abs_program, "-c", "pass"]) self.assertEqual(exitcode, 0) + # absolute bytes path as a string + cmd = b"'" + abs_program + b"' -c pass" + exitcode = subprocess.call(cmd, shell=True) + self.assertEqual(exitcode, 0) + # bytes program, unicode PATH env = os.environ.copy() env["PATH"] = path diff --git a/Misc/NEWS b/Misc/NEWS index da1b75d0274..128efa23e3c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -52,6 +52,8 @@ Core and Builtins Library ------- +- Issue #8513: On UNIX, subprocess supports bytes command string. + - Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall. - Issue #11140: Lock.release() now raises a RuntimeError when attempting