Commit 2eb0cb47 authored by Gregory P. Smith's avatar Gregory P. Smith Committed by GitHub

bpo-22635: Update the getstatusoutput docstring. (#3435)

To match the documentation updates already made.
Also renames the local variable used within to match
what it actually holds.
parent 888bbdc1
...@@ -38,7 +38,7 @@ check_output(...): Same as check_call() but returns the contents of ...@@ -38,7 +38,7 @@ check_output(...): Same as check_call() but returns the contents of
getoutput(...): Runs a command in the shell, waits for it to complete, getoutput(...): Runs a command in the shell, waits for it to complete,
then returns the output then returns the output
getstatusoutput(...): Runs a command in the shell, waits for it to complete, getstatusoutput(...): Runs a command in the shell, waits for it to complete,
then returns a (status, output) tuple then returns a (exitcode, output) tuple
""" """
import sys import sys
...@@ -492,7 +492,7 @@ def list2cmdline(seq): ...@@ -492,7 +492,7 @@ def list2cmdline(seq):
# #
def getstatusoutput(cmd): def getstatusoutput(cmd):
""" Return (status, output) of executing cmd in a shell. """Return (exitcode, output) of executing cmd in a shell.
Execute the string 'cmd' in a shell with 'check_output' and Execute the string 'cmd' in a shell with 'check_output' and
return a 2-tuple (status, output). The locale encoding is used return a 2-tuple (status, output). The locale encoding is used
...@@ -506,19 +506,21 @@ def getstatusoutput(cmd): ...@@ -506,19 +506,21 @@ def getstatusoutput(cmd):
>>> subprocess.getstatusoutput('ls /bin/ls') >>> subprocess.getstatusoutput('ls /bin/ls')
(0, '/bin/ls') (0, '/bin/ls')
>>> subprocess.getstatusoutput('cat /bin/junk') >>> subprocess.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory') (1, 'cat: /bin/junk: No such file or directory')
>>> subprocess.getstatusoutput('/bin/junk') >>> subprocess.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found') (127, 'sh: /bin/junk: not found')
>>> subprocess.getstatusoutput('/bin/kill $$')
(-15, '')
""" """
try: try:
data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT) data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT)
status = 0 exitcode = 0
except CalledProcessError as ex: except CalledProcessError as ex:
data = ex.output data = ex.output
status = ex.returncode exitcode = ex.returncode
if data[-1:] == '\n': if data[-1:] == '\n':
data = data[:-1] data = data[:-1]
return status, data return exitcode, data
def getoutput(cmd): def getoutput(cmd):
"""Return output (stdout or stderr) of executing cmd in a shell. """Return output (stdout or stderr) of executing cmd in a shell.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment