Python: Call shell command

By Xah Lee. Date: . Last updated: .

Call shell command, wait, get output

# call shell command and get its output

import subprocess

# on windows
# output = subprocess.run(["dir"], text=True, shell=True, check=True)

# on linux
output = subprocess.run(["ls -al"], text=True, shell=True, check=True)

print(output)

Python, System Call Related