Created
February 13, 2012 08:09
-
-
Save xiaom/1814878 to your computer and use it in GitHub Desktop.
call command from python
This file contains hidden or 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
import subprocess | |
def call_command(command): | |
process = subprocess.Popen(command.split(' '), | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
return process.communicate() | |
# An example | |
if __name__ == "__main__": | |
cmd = "rsync -avz %s %s"%(src, dest) | |
print cmd | |
_, err = call_command(cmd) | |
if err!='': print err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment