MCPcopy Index your code
hub / github.com/python/cpython / getstatusoutput

Function getstatusoutput

Lib/subprocess.py:655–685  ·  view source on GitHub ↗

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 to decode the output and process newlines. A trailing newline is stripped from the output. The exit

(cmd, *, encoding=None, errors=None)

Source from the content-addressed store, hash-verified

653#
654
655def getstatusoutput(cmd, *, encoding=None, errors=None):
656 """Return (exitcode, output) of executing cmd in a shell.
657
658 Execute the string 'cmd' in a shell with 'check_output' and
659 return a 2-tuple (status, output). The locale encoding is used
660 to decode the output and process newlines.
661
662 A trailing newline is stripped from the output.
663 The exit status for the command can be interpreted
664 according to the rules for the function 'wait'. Example:
665
666 >>> import subprocess
667 >>> subprocess.getstatusoutput('ls /bin/ls')
668 (0, '/bin/ls')
669 >>> subprocess.getstatusoutput('cat /bin/junk')
670 (1, 'cat: /bin/junk: No such file or directory')
671 >>> subprocess.getstatusoutput('/bin/junk')
672 (127, 'sh: /bin/junk: not found')
673 >>> subprocess.getstatusoutput('/bin/kill $$')
674 (-15, '')
675 """
676 try:
677 data = check_output(cmd, shell=True, text=True, stderr=STDOUT,
678 encoding=encoding, errors=errors)
679 exitcode = 0
680 except CalledProcessError as ex:
681 data = ex.output
682 exitcode = ex.returncode
683 if data[-1:] == '\n':
684 data = data[:-1]
685 return exitcode, data
686
687def getoutput(cmd, *, encoding=None, errors=None):
688 """Return output (stdout or stderr) of executing cmd in a shell.

Callers 1

getoutputFunction · 0.85

Calls 1

check_outputFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…