title: scrambled output from a child process run from subprocess
body: <p>I'm using the following code to run another python script. The problem I'm facing is that the output of that script is coming out in an unorderly manner.
  While running it from the command line, I get the correct output i.e. :</p>
  
  <blockquote>
    <p><em>some output here</em><br>
    Editing xml file and saving changes<br>
    Uploading xml file back..</p>
  </blockquote>
  
  <p>While running the script using subprocess, am getting some of the output in reverse order:</p>
  
  <blockquote>
    <p><em>correct output till here</em><br>
    Uploading xml file back..<br>
    Editing xml file and saving changes<br></p>
  </blockquote>
  
  <p>The script is executing without errors and making the right changes. So I think the culprit might be the code that is calling the child script, but I can't find the problem:</p>
  
  <pre><code>    cmd = "child_script.py"
      proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
      (fout ,ferr) = ( proc.stdout, proc.stderr )
      print "Going inside while - loop"
      while True:
          line = proc.stdout.readline()
          print line
          fo.write(line)
          try : 
              err = ferr.readline()
              fe.write(err)
          except Exception, e:
              pass
          if not line:
              pass
              break
  </code></pre>
  
  <p>[EDIT]: fo and fe are file handles to output and error logs. Also the script is being run on Windows.Sorry for missing these details.</p>