Python Notes and Examples

Managing Processes

import os, subprocess

os.chdir(os.environ['HOME'])

# Shell-out. Raises an exception if exit code not zero.
subprocess.check_call(['tar', 'czf', 'docs.tar.gz', 'docs'])

# Returns output from running shell command:
some_output = subprocess.check_output(['ls', '-l'])