Last active
April 29, 2017 20:42
-
-
Save KenDUemura/4b45f6339dc6e85fd506a86947053252 to your computer and use it in GitHub Desktop.
gist copied from http://stackoverflow.com/questions/1996518/retrieving-the-output-of-subprocess-call
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 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