title: python subprocess.call and pipes
body: <p>I have a script in which I am trying to use subprocess.call to execute a series of shell commands, but which appears to have some commands omitted when executed.  </p>
  
  <p>Specifically:</p>
  
  <pre><code>#!/usr/bin/python
  import tempfile
  import subprocess
  import os
  import re
  
  
  grepfd, grepfpath = tempfile.mkstemp(suffix=".xx")
  sedfd,  sedfpath  = tempfile.mkstemp(suffix=".xx")
  
  # grepoutfile = open( grepfpath, 'w')
  sedoutfile  = open( sedfpath,  'w' )
  
  subprocess.call(['cp','/Users/bobby/Downloads/sample.txt', grepfpath])
  
  sedcmd = [ 'sort', 
             grepfpath,
             '|', 
             'uniq',
             '|',
             'sed',
             '-e',
             '"s/bigstring of word/ smaller /"',
             '|',
             'column',
             '-t',
             '-s',
             '"=&gt;"' ]
  
  print "sedcmd = ", sedcmd
  subprocess.call( ['ls', grepfpath ] )
  subprocess.call( ['sort', '|', 'uniq' ], stdin = grepfd )
  subprocess.call( sedcmd,  stdout = sedoutfile )
  </code></pre>
  
  <p>And it generates this as output:</p>
  
  <p>python d3.py</p>
  
  <p>sedcmd =  ['sort', /var/folders/3h/_0xwt5bx0hx8tgx06cmq9h_4f183ql/T/tmp5Gp0ff.xx', '|', 'uniq', '|', 'sed', '-e', '"s/bigstring of word/ smaller /"', '|', 'column', '-t', '-s', '"=>"']
  /var/folders/3h/_0xwt5bx0hx8tgx06cmq9h_4f183ql/T/tmp5Gp0ff.xx
  sort: open failed: |: No such file or directory<br>
  sort: invalid option -- e
  Try `sort --help' for more information.</p>
  
  <p>The first 'sort: open failed: |:No such file... is from the first subprocess call ['sort','|','uniq'], stdin = grepfd )
  The 'sort: invalid option -- e  .. is from the second subprocess call (sedcmd).</p>
  
  <p>I have seen a lot of examples that use pipes in this context -- so what am I doing wrong?<br>
  Thanks!</p>