On this page
os.system
Prev: os.symlink | Up: os | Next: os.terminal_size
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.system
Tags: #public #python3 #stdlib #os
Import
import os
from os import system
Signature & Overview
os.system(command)
Execute the command in a subshell.
Usage
import os
rc = os.system("true") if os.name == "posix" else os.system("ver > NUL")
assert rc == 0
Gotchas
- Legacy—prefer
subprocess.run():os.system()runs through a shell (injection risk), cannot capture stdout/stderr, and returns an OS-encoded wait status on Unix rather than a plain exit code.
REPL Inspect
from os import system
help(system)
Linked from
Related notes
- tuts/python3/stdlib_module/os/symlink Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/terminal_size Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib