Catch the output of child process' child process by subprocess module
<p>I'm using Popen.communicate to test students' programs.  I found an annoying fact, that this API might not be able to catch output of child process's child process.</p>

<p>For example, one student wrote some code like this</p>

<pre><code>    if ((pid = fork()) == 0)
    {
        pwd(cwd);
        exit(0);
    }
    else
    {
        int ReturnCode;
        while (pid != wait(&amp;ReturnCode))
        {
            ;
        }
    }
</code></pre>

<p>And pwd() simply prints the current directory</p>

<pre><code>void pwd(const char *cwd)
{
    //printf("Current working directory is:\n");
    printf("%s\n", cwd);
}
</code></pre>

<p>My testing script simply couldn't get any output by using Popen.communicate.  As programs that do not use multiprocess could pass my test script.  I guess the only reason of the problem would be Popen.communicate some how couldn't get the output of a child process's child process.</p>

<p>Is there any walk around for this?</p>

<p>Edit:</p>

<p>This is my testing script</p>

<pre><code>cd_command = '''cd /etc
pwd
cd /var
pwd
'''
def test_cd_pwd(self):
    # self.sh is the process that we are testing.
    self.out, self.err = self.sh.communicate(self.cd_command)
    self.assert_(self.out = "/etc\n/var\n")
</code></pre>
