Skip to content

Instantly share code, notes, and snippets.

@wakwanza
Created March 26, 2015 23:59
Show Gist options
  • Save wakwanza/d4c1ebee9ad6cacbf582 to your computer and use it in GitHub Desktop.
Save wakwanza/d4c1ebee9ad6cacbf582 to your computer and use it in GitHub Desktop.
shlex and subprocess Popen in python to execute external command and get return code plus result.
#!/usr/bin/python
import subprocess, sys, shlex
def main(argv):
args = shlex.split(argv)
op = subprocess.Popen(args,stdout=subprocess.PIPE)
result, err = op.communicate()
op.wait()
tw = op.returncode
# Use the result , error and return code here for extra processing
if __name__ == "__main__":
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment