title: log syntax errors and uncaught exceptions for a python subprocess and print them to the terminal
body: <h2>The Problem</h2>
  
  <p>I've been trying to write a program that logs uncaught exceptions and syntax errors for a subprocess. Easy, right? Just pipe <code>stderr</code> to the right place. </p>
  
  <p><em>However</em>, the subprocess is another python program- I'll call it <code>test.py</code>- that needs to run as if its output/errors are not being captured. That is, running the logger program needs to seem like the user has just run <code>python test.py</code> as normal.</p>
  
  <p>Further complicating the issue is <a href="http://bugs.python.org/issue1927" rel="nofollow noreferrer">the problem</a> that <code>raw_input</code> actually gets sent to <code>stderr</code> if <code>readline</code> is not used. Unfortunately, I can't just <code>import readline</code>, since I don't have control over the files that are being run using my error logger.</p>
  
  <p><strong>Notes:</strong></p>
  
  <ul>
  <li>I am fairly restricted on the machines that this code will run on. I can't install <code>pexpect</code> or edit the <code>*customize.py</code> files (since the program will be run by a lot of different users). I really feel like there should be a stdlib solution anyway though...</li>
  <li>This only has to work on macs. </li>
  <li>The motivation for this is that I'm part of a team researching the errors that new programmers get. </li>
  </ul>
  
  <h2>What I've Tried</h2>
  
  <p>I've tried the following methods, without success:</p>
  
  <ul>
  <li>just using <code>tee</code> as in the question <a href="https://stackoverflow.com/questions/692000/how-do-i-write-stderr-to-a-file-while-using-tee-with-a-pipe">How do I write stderr to a file while using &quot;tee&quot; with a pipe?</a> (failed to produce <code>raw_input</code> prompts); python implementations of <code>tee</code> that I found in several SO questions had similar issues</li>
  <li>overwriting <code>sys.excepthook</code> (failed to make it work for a subprocess)</li>
  <li><a href="https://stackoverflow.com/questions/4984428/python-subprocess-get-childrens-output-to-file-and-terminal">this question's</a> top answer seemed promising, but it failed to display <code>raw_input</code> prompts correctly.</li>
  <li>the <a href="http://docs.python.org/library/logging.html" rel="nofollow noreferrer">logging module</a> seems useful for actually writing to a log file, but doesn't seem to get at the crux of the issue</li>
  <li>custom stderr readers</li>
  <li>endless googling</li>
  </ul>