Skip to content

bpo-22635: Update the getstatusoutput docstring. #3435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
getoutput(...): Runs a command in the shell, waits for it to complete,
then returns the output
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
Expand Down Expand Up @@ -492,7 +492,7 @@ def list2cmdline(seq):
#

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
return a 2-tuple (status, output). The locale encoding is used
Expand All @@ -506,19 +506,21 @@ def getstatusoutput(cmd):
>>> subprocess.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> 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')
(256, 'sh: /bin/junk: not found')
(127, 'sh: /bin/junk: not found')
>>> subprocess.getstatusoutput('/bin/kill $$')
(-15, '')
"""
try:
data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT)
status = 0
exitcode = 0
except CalledProcessError as ex:
data = ex.output
status = ex.returncode
exitcode = ex.returncode
if data[-1:] == '\n':
data = data[:-1]
return status, data
return exitcode, data

def getoutput(cmd):
"""Return output (stdout or stderr) of executing cmd in a shell.
Expand Down