title: Python subprocess on Windows 7 64bit - no output when stdout=PIPE
body: <p>Apologies for another question about Python subprocesses, but I couldn't find an answer to this one.</p>
  
  <p>I am having trouble with some Python code which calls a subprocess on Windows 7 64-bit. When the subprocess's stdout is sent to a pipe, no output is produced. The subprocess appears to run and terminate without problems, it just doesn't produce any output.</p>
  
  <p>EDIT: The same code works correctly on WinXP 32bit, so I updated the question title.</p>
  
  <pre><code># (listing 1)
  from subprocess import *
  #cmdline= (a valid command line)
  proc = Popen(cmdline,shell=True,stdout=PIPE,stderr=PIPE)
  out, err = proc.communicate()
  print( out )
  print( err )
  </code></pre>
  
  <p>This gives output</p>
  
  <pre><code>out:
  
  err:
  </code></pre>
  
  <p>However, when the subprocess's output is not piped, it produces output as expected:</p>
  
  <pre><code># (listing 2)
  proc = Popen(cmdline,shell=True)
  proc.communicate()
  </code></pre>
  
  <p>This gives the expected output to console.</p>
  
  <p>I'm confident the executable is actually writing its output to stdout. I have the C source code, and I added the line:</p>
  
  <pre><code>fprintf(stdout, "HELLO");
  </code></pre>
  
  <p>Again, "HELLO" is seen when running listing 2, but not listing 1.</p>
  
  <p>I also tried making a new C++ executable and calling that from cmdline:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; "HELLO" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The same thing still happens - "HELLO" is seen when running listing 2, but not listing 1.</p>
  
  <p>If I set cmdline to 'dir', the expected thing happens for both listing 1 and listing 2 - directory contents are printed to the console.</p>
  
  <p>Other things I tried: Python 3.3 and Python 2.7 (same results); bufsize=0 (same results); checking proc.returncode (it's 0, as expected); removing stderr=PIPE (in which case listing 1 gives "err: None" as expected).</p>
  
  <p>EDIT - I also tried out = proc.stdout instead of the communicate() method with the same results. Python documentation and other questions suggest the communicate() method is the right one to use.</p>