Skip to content

Instantly share code, notes, and snippets.

@tlatsas
Last active December 19, 2015 06:09
Show Gist options
  • Save tlatsas/5909665 to your computer and use it in GitHub Desktop.
Save tlatsas/5909665 to your computer and use it in GitHub Desktop.
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