title: Getting STDOUT and STDERR from subprocess.Popen synchronously
body: <p>I'm looking to write some simple utilities that call native executables/scripts. I'm already fairly familiar with using <code>subprocess.Popen</code> to open processes, but I don't understand how to effectively get access to the subprocess' STDOUT and STDERR synchronously in Python. I understand that I can pass it a <code>file</code>-like object and it'll work fine, but how exactly do I do that? I don't want to write it to an actual filesystem file, so how do I do this? Do I need the <code>mmap.mmap()</code> memory file API?</p>
  
  <p>I'd like to do something like this:</p>
  
  <pre><code>class CoolReader():
  
      def __init__(self, target):
          self.target = target 
  
      def write(self, output):
          self.target.append({timestamp: time.time(), value: output})
  
  stdoutLines = []
  stderrLines = []
  
  stdoutReader = CoolReader(stdoutLines)
  stderrReader = CoolReader(stderrLines)
  
  subprocess.Popen("ls", stdout=stdoutReader, stderr=stderrReader)
  </code></pre>
  
  <p>Is there a better way of doing this? I'd basically like to have a listener be fired every time a line is written to STDOUT or STDERR to synchronously write file lines to an array or something. How can I/should I do this?</p>