Created
March 26, 2015 23:59
-
-
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.
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/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