Created
March 30, 2012 15:23
-
-
Save skinp/2252254 to your computer and use it in GitHub Desktop.
Run a command in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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