Skip to content

Instantly share code, notes, and snippets.

@skinp
Created March 30, 2012 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skinp/2252254 to your computer and use it in GitHub Desktop.
Save skinp/2252254 to your computer and use it in GitHub Desktop.
Run a command in python
#!/usr/bin/env python
import subprocess
import sys
def run(command):
if not command:
raise Exception("Commande vide")
else:
print command
p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
out, err = p.communicate()
return out
if __name__ == "__main__":
print run(" ".join(sys.argv[1:])),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment