Skip to content

Instantly share code, notes, and snippets.

@algas
Last active August 29, 2015 14:06
Show Gist options
  • Save algas/c332790830967090c476 to your computer and use it in GitHub Desktop.
Save algas/c332790830967090c476 to your computer and use it in GitHub Desktop.
Python Subprocess Example
import subprocess
import collections
CommandResponse = collections.namedtuple('CommandResponse', ['code', 'out', 'err'])
def run_command(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sout, serr = p.communicate()
return CommandResponse(p.returncode, sout, serr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment