Python Glossary Русский

all Python 3subprocessfunction

subprocess.call()

running processes

The legacy way to run a command and wait for it: returns the exit status as a number and does not check it.

Syntax

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None)

call does not notice a failing command: it returns 1 or 2, and if nobody looks at the result the failure passes silently. Do not try to capture output with stdout=PIPE here — nothing reads the pipe, and a large output deadlocks the child; use run(capture_output=True) for that. In new code call(...) equals run(...).returncode.

Examples

import subprocess, sys
code = subprocess.call([sys.executable, '-c', 'import sys; sys.exit(3)'])
print(code)  # → 3
import subprocess, sys
rc = subprocess.call([sys.executable, '-c', 'print(42)'],
                     stdout=subprocess.DEVNULL)  # вывод подавлен
print(rc)  # → 0

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy