Created
October 31, 2015 10:27
-
-
Save gregelin/ee495c56aa71eb4d4f3a to your computer and use it in GitHub Desktop.
Python return (status, output) of executing cmd in a shell.
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
def getstatusoutput(cmd): | |
"""Return (status, output) of executing cmd in a shell.""" | |
"""This new implementation should work on all platforms.""" | |
import subprocess | |
pipe = subprocess.Popen(cmd, shell=True, universal_newlines=True, | |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
output = str.join("", pipe.stdout.readlines()) | |
sts = pipe.wait() | |
if sts is None: | |
sts = 0 | |
return sts, output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment