On this page
  1. subprocess.run
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

subprocess.run

Prev: subprocess.Popen | Up: subprocess | Next: subprocess.SubprocessError
Rel: subprocess.call, subprocess.CalledProcessError, subprocess.check_call, subprocess.check_output
Ref: docs.python.org — subprocess.run
Tags: #public #python3 #stdlib #subprocess


Import

import subprocess
from subprocess import run

Signature & Overview

subprocess.run(*popenargs, input=None, capture_output=False, timeout=None, check=False, **kwargs)

Run command with arguments and return a CompletedProcess instance.

Usage

import subprocess
import sys

res = subprocess.run(
    [sys.executable, "-c", "print(2 + 2)"],
    capture_output=True,
    text=True,
    check=True,
    timeout=10,
)
assert res.stdout.strip() == "4"

Gotchas

REPL Inspect

from subprocess import run
help(run)

Linked from

Related notes