diff -r fe828884a077 Lib/subprocess.py --- a/Lib/subprocess.py Sun Nov 03 14:22:14 2013 +0000 +++ b/Lib/subprocess.py Sun Nov 03 17:23:08 2013 +0000 @@ -146,17 +146,16 @@ Return (status, output) of executing cmd in a shell. Execute the string 'cmd' in a shell with os.popen() and return a 2-tuple - (status, output). cmd is actually run as '{ cmd ; } 2>&1', so that the - returned output will contain output or error messages. A trailing newline - is stripped from the output. The exit status for the command can be - interpreted according to the rules for the C function wait(). Example: + (status, output). Any trailing newlines are stripped from the output. + The exit status for the command can be interpreted according to the rules + for the C function wait(). Example: >>> subprocess.getstatusoutput('ls /bin/ls') - (0, '/bin/ls') + (0, b'/bin/ls') >>> subprocess.getstatusoutput('cat /bin/junk') - (256, 'cat: /bin/junk: No such file or directory') + (256, b'cat: /bin/junk: No such file or directory') >>> subprocess.getstatusoutput('/bin/junk') - (256, 'sh: /bin/junk: not found') + (256, b'sh: /bin/junk: not found') getoutput(cmd): Return output (stdout or stderr) of executing cmd in a shell. @@ -165,7 +164,7 @@ value is a string containing the command's output. Example: >>> subprocess.getoutput('ls /bin/ls') - '/bin/ls' + b'/bin/ls' check_output(*popenargs, **kwargs): Run command with arguments and return its output. @@ -701,15 +700,13 @@ (256, 'sh: /bin/junk: not found') """ try: - data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT) + data = check_output(cmd, shell=True, stderr=STDOUT) status = 0 except CalledProcessError as ex: data = ex.output status = ex.returncode - if data[-1:] == '\n': - data = data[:-1] + data = data.rstrip(b"\r\n") return status, data - def getoutput(cmd): """Return output (stdout or stderr) of executing cmd in a shell. diff -r fe828884a077 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Sun Nov 03 14:22:14 2013 +0000 +++ b/Lib/test/test_subprocess.py Sun Nov 03 17:23:08 2013 +0000 @@ -2157,13 +2157,11 @@ def test_terminate_dead(self): self._kill_dead_process('terminate') - class CommandTests(unittest.TestCase): def test_getoutput(self): - self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy') + self.assertEqual(subprocess.getoutput('echo xyzzy'), b'xyzzy') self.assertEqual(subprocess.getstatusoutput('echo xyzzy'), - (0, 'xyzzy')) - + (0, b'xyzzy')) # we use mkdtemp in the next line to create an empty directory # under our exclusive control; from that, we can invent a pathname # that we _know_ won't exist. This is guaranteed to fail. diff -r fe828884a077 Misc/NEWS --- a/Misc/NEWS Sun Nov 03 14:22:14 2013 +0000 +++ b/Misc/NEWS Sun Nov 03 17:23:08 2013 +0000 @@ -31,6 +31,8 @@ Library ------- +- Issue #9922: subprocess.get[status]output now always returns bytes + - Issue #6157: Fixed tkinter.Text.debug(). tkinter.Text.bbox() now raises TypeError instead of TclError on wrong number of arguments. Original patch by Guilherme Polo.