Skip to content

Instantly share code, notes, and snippets.

@javierarilos
Created October 13, 2015 11:41
Show Gist options
  • Save javierarilos/05ef20d9fb266d241521 to your computer and use it in GitHub Desktop.
Save javierarilos/05ef20d9fb266d241521 to your computer and use it in GitHub Desktop.
Execute a Bash command in python, getting back return code, stdin and stdout.
import subprocess
p = subprocess.Popen(['ls', '-la'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
o, e = p.communicate()
print "Executed command ls -la with returncode", p.returncode
print " stdout ", o
print " error ", e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment