popen3 and return code
<p>I want to get stdout and stderr of a command along with the return code. 
Can someone point me to a python function that already accomplishes this?</p>

<p>I modified a function that I found on this site as follows -- but I am not able to grab the return code of the command. In this snippet, sts always seems to be 0.</p>

<pre><code>def Getstatusoutput(cmd):
    """Return (status, output) of executing cmd in a shell."""

    import sys
    mswindows = (sys.platform == "win32")

    import os
    if not mswindows:
        cmd = '{ ' + cmd + '; }'

    fi,fo,fe=os.popen3(cmd)
    textOut = fo.read()
    textErr = fe.read()
    sts = fo.close()
    if sts is None: sts = 0
    if textOut[-1:] == '\n': textOut = textOut[:-1]
    return sts, textOut, textErr  
</code></pre>
