Skip to content

Instantly share code, notes, and snippets.

@colematt
Last active November 1, 2022 20:25
Show Gist options
  • Save colematt/0846ffc2ed86151053399f0ed8e6d78e to your computer and use it in GitHub Desktop.
Save colematt/0846ffc2ed86151053399f0ed8e6d78e to your computer and use it in GitHub Desktop.
[Run a process as a subprocess of the python interpreter] #python3
import argparse
import subprocess
import sys
"""
Run a command and its arguments as a subprocess of the python interpreter.
"""
if __name__ == "__main__":
# Capture a subprocess instance
cp = subprocess.run(
sys.argv[1:],
stdout=subprocess.PIPE)
# Print the subprocess instance's output to standard output
print(cp.stdout.decode(),end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment