title: buffering subprocess output to a file: io.UnsupportedOperation: fileno
body: <p>I would like to buffer an output of <code>grep</code> to a buffer and then read it with <code>pandas</code> to avoid loading a huge original file into memory:</p>
  
  <pre><code>import subprocess
  import io
  import pandas as pd
  
  firstfile = "~/references/rs_hg19.snps.uniq.bed"
  outf = io.StringIO("")
  p0 = subprocess.Popen(('grep', '-P', "chr22\\t", firstfile), stdout=subprocess.PIPE)
  p1 = subprocess.call(["head", "-n5", ], stdin=p0.stdout, stdout= outf)
  p0.wait()
  print(pd.read_table(outf)
      )
  </code></pre>
  
  <p>I am getting an error:</p>
  
  <pre><code>Traceback (most recent call last)
    File "test.py", line 9, in &lt;module&gt;
      p1 = subprocess.call(["head", "-n1", ], stdin=p0.stdout, stdout= outf)
    File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 520, in call
      with Popen(*popenargs, **kwargs) as p:
    File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 786, in __init__
      errread, errwrite) = self._get_handles(stdin, stdout, stderr)
    File "/opt/rh/python33/root/usr/lib64/python3.3/subprocess.py", line 1294, in _get_handles
      c2pwrite = stdout.fileno()
  io.UnsupportedOperation: fileno
  </code></pre>
  
  <p>even though I run it directly, <a href="https://stackoverflow.com/questions/31080829/python-error-io-unsupportedoperation-fileno">not from any IDE</a>.</p>
  
  <p>Any ideas / suggestions?</p>
  
  <p>System 1: CentOS6.7, Python3.3</p>
  
  <p>System 2: MacOSX10.10.5, Python3.5</p>