subprocess.run is the recommended way to spawn a process in Python
Answer: The subprocess module allows you to spawn new processes. It can connect to their input/output/error pipes, and obtain their return codes. For use cases it can handle, the recommended approach is the run function.
subprocess.run(["ls", "-l"]) does not capture output and returns a CompletedProcess. subprocess.run(["ls", "-l", "/dev/null"], capture_output=True) captures output. The docs also show subprocess.run("exit 1", shell=True, check=True) raising CalledProcessError.
This module intends to replace several older modules and functions, including os.system and os.spawn*.
See also
Claims
- id: C1 claim: subprocess lets you spawn processes and obtain return codes. source: S1 evidence: "spawn new processes, connect to their"
- id: C2 claim: The recommended approach is the run function. source: S2 evidence: "The recommended approach to invoking subprocesses is to use the :func:
run"
- id: C3 claim: run can be called with a list such as ["ls", "-l"]. source: S2 evidence: "subprocess.run([\"ls\", \"-l\"]) # doesn't capture output"
- id: C4 claim: capture_output=True collects output on CompletedProcess. source: S2 evidence: "subprocess.run([\"ls\", \"-l\", \"/dev/null\"], capture_output=True)"
Sources
- [S1] subprocess — Subprocess management. Python docs. https://docs.python.org/3/library/subprocess.html . License: PSF-2.0. Accessed 2026-11-16.
- [S2] subprocess.rst (CPython docs). python/cpython (GitHub). https://github.com/python/cpython/blob/main/Doc/library/subprocess.rst . License: PSF-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, subprocess — Subprocess management, PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), subprocess.rst (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, subprocess — Subprocess management, PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), subprocess.rst (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE).
Cite this
iinventedlight. 2026. "subprocess.run is the recommended way to spawn a process in Python." iinventedlight Library, iil:note:7w6mgdn5, version of 2026-11-16. https://iinventedlight.com/library/notes/python-subprocess/. License: CC-BY-4.0.
@misc{iil_note_7w6mgdn5,
author = {{iinventedlight}},
title = {{subprocess.run is the recommended way to spawn a process in Python}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/python-subprocess/},
note = {Permanent ID iil:note:7w6mgdn5. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-subprocess.md.