Get output and return codes of multiple interdependent commands using subprocess
<pre><code>import subprocess
with open ("log.txt",'a') as log:
    output = subprocess.Popen("ech ;echo hello", shell=True, stdout=log, stderr=subprocess.STDOUT)
    print output.wait() # prints  0
</code></pre>

<p><code>ech</code> writes "/bin/sh: ech: command not found" into "log.txt". But the return code is 0 (SUCCESS) because the last command was successful. I want to get individual command return codes and not the return code of just the last command. </p>

<p>Also, assume that the commands are dependent - 
For example: <code>cd .. ; pwd</code> - They should not be split and run as two subprocess calls, because then <code>pwd</code> would not take into account the effect of <code>cd ..</code></p>

<p>The example just above is only for clarification purposes. Please don't recommend solving it by using <code>cwd</code>.</p>