title: catching stdout in realtime from subprocess
body: <p>I want to <code>subprocess.Popen()</code> rsync.exe in Windows, and print the stdout in Python.</p>
  
  <p>My code works, but it doesn't catch the progress until a file transfer is done! I want to print the progress for each file in real time.</p>
  
  <p>Using Python 3.1 now since I heard it should be better at handling IO.</p>
  
  <pre><code>import subprocess, time, os, sys
  
  cmd = "rsync.exe -vaz -P source/ dest/"
  p, line = True, 'start'
  
  
  p = subprocess.Popen(cmd,
                       shell=True,
                       bufsize=64,
                       stdin=subprocess.PIPE,
                       stderr=subprocess.PIPE,
                       stdout=subprocess.PIPE)
  
  for line in p.stdout:
      print("&gt;&gt;&gt; " + str(line.rstrip()))
      p.stdout.flush()
  </code></pre>