MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getstatusoutput

Function getstatusoutput

tools/python-3.11.9-amd64/Lib/subprocess.py:649–679  ·  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. Th

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

Source from the content-addressed store, hash-verified

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