Skip to content

Instantly share code, notes, and snippets.

@xiaom
Created February 13, 2012 08:09
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 xiaom/1814878 to your computer and use it in GitHub Desktop.
Save xiaom/1814878 to your computer and use it in GitHub Desktop.
call command from python
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