Skip to content

Instantly share code, notes, and snippets.

@KenDUemura
Last active April 29, 2017 20:42
Show Gist options
  • Save KenDUemura/4b45f6339dc6e85fd506a86947053252 to your computer and use it in GitHub Desktop.
Save KenDUemura/4b45f6339dc6e85fd506a86947053252 to your computer and use it in GitHub Desktop.
import shlex
from subprocess import Popen, PIPE
def run_shell(cmd):
"""
Execute the external command and get its exitcode, stdout and stderr.
"""
args = shlex.split(cmd)
proc = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
rc = proc.returncode
#
return rc, out, err
cmd = "..." # arbitrary external command, e.g. "python mytest.py"
rc, out, err = run_shell(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment