On this page
subprocess.CompletedProcess
Prev: subprocess.check_output | Up: subprocess | Next: subprocess.getoutput
Rel: subprocess.call, subprocess.CalledProcessError, subprocess.check_call, subprocess.check_output
Ref: docs.python.org — subprocess.CompletedProcess
Tags: #public #python3 #stdlib #subprocess
Import
import subprocess
from subprocess import CompletedProcess
Signature & Overview
subprocess.CompletedProcess(args, returncode, stdout=None, stderr=None)
A process that has finished running.
Methods & Attributes
CompletedProcess.check_returncode(self)— Raise CalledProcessError if the exit code is non-zero.
Usage
import subprocess
import sys
res = subprocess.run([sys.executable, "-c", "print('ok')"], capture_output=True, text=True, check=True)
assert isinstance(res, subprocess.CompletedProcess)
assert res.returncode == 0 and res.stdout.strip() == "ok"
Gotchas
- Returned by
subprocess.run(): Exposes.args,.returncode,.stdout,.stderr, and.check_returncode(). stdout/stderrareNoneby default: Only populated whencapture_output=Trueorstdout=PIPE/stderr=PIPEis passed.
REPL Inspect
from subprocess import CompletedProcess
help(CompletedProcess)
Linked from
Related notes
- tuts/python3/stdlib_module/subprocess/call Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/CalledProcessError Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_call Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_output Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/getoutput 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/getstatusoutput shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/Popen shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/run shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/SubprocessError shared tags: #stdlib, #subprocess