title: Handling Shell Redirection in Python subprocess.Popen()
body: <p>I'm developing a Python (2.7) module which will allow users to either run their commands locally or submit a job to a load sharing facility (like LSF, but home grown). In this situation I want the users to be able to submit their commands like so:</p>
  
  <pre><code>cmd = 'convert_something.tcl some_file &gt;! output_file'
  </code></pre>
  
  <p>This makes the conversion of their scripts (Tcl, Perl, Python, C/C++) easier. (I foresee changing that in the future, but for now...) The subprocess.Popen() command looks like this:</p>
  
  <pre><code>args = cmd.split()
  p = subprocess.Popen(args, shell=True)
  </code></pre>
  
  <p>However, no matter how a play with the arguments to Popen, I cannot get redirection to work. I'm currently working in the tcsh shell, but I've also tried bash. I've tried specifying the shell, like so:</p>
  
  <pre><code>p = subprocess.Popen(args, executable='/bin/bash', pre_exec=oc.setsid)
  </code></pre>
  
  <p>But it gives me an error from the executing program, which I think I expect to happen. I've read and re-read the documentation and searched, but no luck.</p>
  
  <p>I must be missing something obvious, because I recall doing this before (and it worked). Any suggestions would be appreciated.</p>