I came across this great replacment for the getstatusoutput()
function in Python 2.* which works equally well on Unix and Windows. However, I think there is something wrong with the way the output
is constructed. It only returns the last line of the output, but I can't figure out why. Any help would be awesome.
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, stdout=subprocess.PIPE, shell=True, universal_newlines=True)
output = "".join(pipe.stdout.readlines())
sts = pipe.returncode
if sts is None: sts = 0
return sts, output