How to execute a shell command in Python? You can use Python subprocess module to execute windows or Linux commands from within your Python script. Default import subprocess ## Executes ls -l command subprocess.run(["ls", "-l"]) 1234 import subprocess ## Executes ls -l commandsubprocess.run(["ls", "-l"]) Tags: Bash, FAQ, Linux, Python, Shell