Last active
December 19, 2015 06:09
-
-
Save tlatsas/5909665 to your computer and use it in GitHub Desktop.
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 | |
import shlex | |
def _run(command): | |
"""subprocess wrapper to execute system commands, command is expected as string""" | |
try: | |
p = subprocess.Popen(shlex.split(command), | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output, error = p.communicate() | |
exit_code = p.returncode | |
return (output, error, exit_code) | |
except OSError: | |
# here you whould normaly log the error and raise some custom exception | |
# we return data to keep it simple | |
return (None, "Cannot execute command {0}".format(commad), 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment