← Go Back
To run a program:
Tu execute shell commands:
How to Run a Program or Execute Shell Commands
Using thesubprocess
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
🐍 You might also find interesting: