Skip to content

Instantly share code, notes, and snippets.

@glennzw
Created April 4, 2013 08:26
Show Gist options
  • Save glennzw/5308728 to your computer and use it in GitHub Desktop.
Save glennzw/5308728 to your computer and use it in GitHub Desktop.
Python - calling external programs
if you want the process's exitcode, subprocess.call() returns that. If you want to execute something and raise an exception if it fails, subprocess.check_call() does that. If you want something more complicated, including a conversation with the process you're starting or simply not waiting for the process to end, subprocess.Popen is what you want.
import subprocess
r=subprocess.check_call(["ls"])
r=subprocess.call(["ls"])
r = subprocess.Popen(["ls"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment