Created
May 15, 2014 04:51
-
-
Save terryoy/c6009bbf084eb5fcfedc to your computer and use it in GitHub Desktop.
Python calling OS command line
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
import subprocess | |
def run_program(cmdargs): | |
"""Execute an OS program with arguments(in list form), and return the (returncode, stdout, stderr) result""" | |
p = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output = p.communicate() | |
return p.returncode, output[0], output[1] | |
# example; | |
# run_program(['ls', '-l']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment