subprocess.getstatusoutput
Prev: subprocess.getoutput | Up: subprocess | Next: subprocess.Popen
Rel: subprocess.call, subprocess.CalledProcessError, subprocess.check_call, subprocess.check_output
Ref: docs.python.org — subprocess.getstatusoutput
Tags: #public #python3 #stdlib #subprocess
Import
import subprocess
from subprocess import getstatusoutput
Signature & Overview
subprocess.getstatusoutput(cmd, *, encoding=None, errors=None)
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.
Usage
import subprocess
status, out = subprocess.getstatusoutput("echo ok")
assert status == 0 and out == "ok"
Gotchas
- Runs through the system shell: Avoid with untrusted arguments; combines stdout and stderr into one string and strips a single trailing newline.
- Prefer
subprocess.run([...], capture_output=True, text=True)when you want separate stdout/stderr and no shell parsing.
REPL Inspect
from subprocess import getstatusoutput
help(getstatusoutput)
Linked from
Related notes
- tuts/python3/stdlib_module/subprocess/getoutput Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/Popen Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/subprocess/call Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/CalledProcessError Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_call Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_output Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/CompletedProcess shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/run shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/SubprocessError shared tags: #stdlib, #subprocess