title: Python 3 TypeError: must be str, not bytes with sys.stdout.write()
body: <p>I was looking for a way to run an external process from python script and print its stdout messages during the execution.<br>
  The code below works, but prints no stdout output during runtime. When it exits I am getting the following error:</p>
  
  <blockquote>
    <p>sys.stdout.write(nextline) TypeError:must be str,not bytes</p>
  </blockquote>
  
  <pre><code>p = subprocess.Popen(["demo.exe"],stdout = subprocess.PIPE, stderr= subprocess.PIPE)    
  # Poll process for new output until finished
  while True:
      nextline = p.stdout.readline()
      if nextline == '' and p.poll() != None:
          break
      sys.stdout.write(nextline)
      sys.stdout.flush()
  
  output = p.communicate()[0]
  exitCode = p.returncode
  </code></pre>
  
  <p>I am using python 3.3.2</p>