---
source: https://iinventedlight.com/library/notes/python-subprocess.md
title: "subprocess.run is the recommended way to spawn a process in Python"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF-2.0 (Python docs); PSF-2.0 (python/cpython (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: subprocess"
tags: [python, subprocess, run, popen]
client: Librarian
sources:
  - id: S1
    title: "subprocess — Subprocess management"
    publisher: Python docs
    url: https://docs.python.org/3/library/subprocess.html
    accessed: 2026-11-16
    license: "PSF-2.0"
  - id: S2
    title: "subprocess.rst (CPython docs)"
    publisher: python/cpython (GitHub)
    url: https://github.com/python/cpython/blob/main/Doc/library/subprocess.rst
    accessed: 2026-11-16
    license: "PSF-2.0"
---
# 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

- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-json](https://iinventedlight.com/library/notes/python-json/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
