title: python subprocess read stdout as it executes
body: <p>one of my function in the program checks the md5sum of hashfile</p>
  
  <pre><code>def check():
      print "checking integrity status.."
      md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
      #fopen = open(basefile, "r")
      for f in md5.stdout.readlines():
          fc = f.rstrip("\n")
          sys.stdout.write("\rChecking..." + fc)
          sys.stdout.flush()
  </code></pre>
  
  <p>now what happens is that the whole command is first executed and then for loop reads from md5 using md5.stdout.readlines, as such it is not dynamic i.e. i dont get the output as the command is executed....is there a way i can get the output while the command is in execution...</p>
  
  <p><strong>fixed using glglgl's answer:</strong></p>
  
  <pre><code>def check():
      print "checking integrity status.."
      md5 = subprocess.Popen(["md5sum", "-c", hashfile],shell=False, stdout=subprocess.PIPE)
      #fopen = open(basefile, "r")
      fc = "NULL"
      i = 0
      for f in iter(md5.stdout.readline, ''):
          k = fc
          fc = f.rstrip("\n")
          if "FAILED" in fc:
              print fc
          i = i + 1
          sys.stdout.write("\rChecking... "+ str(i)+ " " + fc + (' ' * (len(k) - len(fc))) )
          sys.stdout.flush()
  </code></pre>