read output from subprocess.Popen in python
<p>I am trying to run the following subprocess.Popen() command in python 2.6</p>

<pre><code>output = subprocess.Popen("psexec -accepteula \\machineName -u username -p password cmd.exe /C fsutil fsinfo drives", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(output.communicate())
</code></pre>

<p>But I get the following result with output.communicate()</p>

<pre><code>('\r\n', '\r\nPsExec v2.11 - Execute processes remotely\r\nCopyright (C) 2001-2014 Mark Russinovich\r\nSysinternals - www.sysinternals.com\r\n\r\nConnecting to machineNameHere...\r\r\rStarting PSEXESVC service on machineNameHere...\r\r\rConnecting with PsExec service on machineNameHere...\r\r\rStarting cmd.exe on machineNameHere...\r\r\r\r\ncmd.exe exited on machineNameHere with error code 0.\r\n')
</code></pre>

<p>When I run the same psexec command from cmd line in windows, I get the correct output.</p>

<pre><code>PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

**Drives: A:\ C:\ D:\**
cmd.exe exited on machineNameHere with error code 0.
</code></pre>

<p>I am looking for the output **Drives: A:\ C:\ D:** even while running the psexec command using subprocess.Popen(). Any way I can do it?</p>

<hr>

<p>Now I narrowed down the issue by running different commands like dir and echo "test". The issue seems to be that Popen is reading only first line into stdout  and not the complete output. Any suggestions on how to fix this?</p>