title: Unable to pass subprocess.PIPE to Process on Windows
body: <p>I have a script that works on linux but is not compatible with Python 3 on windows (Python 3.5.2 is the version tested). The goal of the script is to capture stdout/stderr of a subprocess in realtime. Here is a script that reproduces the error:</p>
  
  <pre><code>import subprocess
  import os
  import sys
  
  from multiprocessing import Process, Queue
  try:
      from Queue import Empty
  except ImportError:
      from queue import Empty  # python 3.x
  
  ON_POSIX = 'posix' in sys.builtin_module_names
  
  
  def enqueue_output(out, q):
      for line in iter(out.readline, b''):
          q.put(line)
      out.close()
  
  
  def output_monitor_queue(out):
      q = Queue()
      p = Process(target=enqueue_output, args=(out, q))
      p.start()
      return q, p
  
  
  def update_from_output_queue(q, out):
      try:
          line = q.get_nowait()
      except Empty:
          return out
  
      out += str(line)
      return out
  
  
  def runit():
      stdout, stderr = '', ''
      proc = subprocess.Popen(['ipconfig.exe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  
      # We need to use subprocesses to capture the IO, otherwise they will block one another
      # i.e. a check against stderr will sit waiting on stderr before returning
      # we use Queues to communicate
      qout, pout = output_monitor_queue(proc.stdout)
      qerr, perr = output_monitor_queue(proc.stderr)
  
      prev_std = None
  
      # Loop until the process is complete + both stdout/stderr have EOFd
      while proc.poll() is None or pout.is_alive() or perr.is_alive():
  
          # Check for updates from either (non-blocking)
          stdout = update_from_output_queue(qout, stdout)
          stderr = update_from_output_queue(qerr, stderr)
  
          # If there are changes, update the db
          if (stdout, stderr) != prev_std:
              print(stdout, stderr)
              prev_std = (stdout, stderr)
  
  
  runit()
  </code></pre>
  
  <p>On running it, the following error is thrown:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "C:\Users\IEUser\Desktop\failed.py", line 62, in 
        runit()   File "C:\Users\IEUser\Desktop\failed.py", line 44, in runit
        qout, pout = output_monitor_queue(proc.stdout)   File "C:\Users\IEUser\Desktop\failed.py", line 23, in output_monitor_queue
        p.start()   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\process.py",
    line 105, in start
        self._popen = self._Popen(self)   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\context.py",
    line 212, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)   File
    "C:\Users\IEUser\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\context.py",
    line 313, in _Popen
        return Popen(process_obj)   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\popen_spawn_win32.py",
    line 66, in <strong>init</strong>
        reduction.dump(process_obj, to_child)   File "C:\Users\IEUser\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\reduction.py",
    line 59, in dump
        ForkingPickler(file, protocol).dump(obj) TypeError: cannot serialize '_io.BufferedReader' object</p>
  </blockquote>
  
  <p>Has anyone encountered this problem and knows a working cross-platform solution?</p>