Skip to content

Instantly share code, notes, and snippets.

@adamatan
Created October 25, 2012 12:16
Show Gist options
  • Save adamatan/3952258 to your computer and use it in GitHub Desktop.
Save adamatan/3952258 to your computer and use it in GitHub Desktop.
Python subprocess call
#!/usr/bin/python
import subprocess as sp
# Pipes used to prevent buffer problems with verbose output.
# stdout is redirected to stderr.
# shell=True allows spaces in 'cmd'.
# communicate() waits for termination and empties buffers into 'output'.
cmd = "ls"
p = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
output = p.communicate()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment