title: bash wrap a piped command with a python script
body: <p>Is there a way to create a python script which wraps an entire bash command including the pipes.</p>
  
  <p>For example, if I have the following simple script</p>
  
  <pre><code>import sys
  print sys.argv
  </code></pre>
  
  <p>and call it like so (from bash or ipython), I get the expected outcome:</p>
  
  <pre><code>[pkerp@pendari trell]$ python test.py ls
  ['test.py', 'ls']
  </code></pre>
  
  <p>If I add a pipe, however, the output of the script gets redirected to the pipe sink:</p>
  
  <pre><code>[pkerp@pendari trell]$ python test.py ls &gt; out.txt
  </code></pre>
  
  <p>And the <code>&gt; out.txt</code> portion is not in sys.argv. I understand that the shell automatically process this output, but I'm curious if there's a way to force the shell to ignore it and pass it to the process being called. </p>
  
  <p>The point of this is to create something like a wrapper for the shell. I'd like to run the commands regularly, but keep track of the strace output for each command (including the pipes). Ideally I'd like to keep all of the bash features, such as tab-completion and up and down arrows and history search, and then just pass the completed command through a python script which invokes a subprocess to handle it.</p>
  
  <p>Is this possible, or would I have to write my own shell to do this?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>It appears I'm asking the exact same thing as <a href="https://stackoverflow.com/questions/20525056/bash-or-other-shell-wrap-all-commands-with-function-script">this question</a>.</p>