subprocess
Run external programs and capture their output.
Easy
import subprocess
r = subprocess.run(["git", "status", "--short"], capture_output=True, text=True, check=True)
print(r.stdout)
Pass arguments as a list and avoid shell=True with user input.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.