← Go Back

How to Run a Program or Execute Shell Commands

Using the subprocess standard module is the recommended way.

To run a program:

>>> import subprocess
>>> subprocess.run(["python", "--version"])
Python 3.12.0
CompletedProcess(args=['python', '--version'], returncode=0)

Tu execute shell commands:

>>> import subprocess
>>> subprocess.run("pwd", shell=True)
/root


subprocess os processes


🐍 You might also find interesting: