title: Can I archive output from ipython's %run (stdout,stderr) and maintain ability to debug interactively?
body: <p>I use <code>ipython --pdb -c '%run script.py'</code> from a bash shell to launch
  <code>script.py</code> in a manner that is very convenient for debugging (the <code>--pdb</code>
  causes <code>ipython</code> to automatically drop into debugger on an exception).</p>
  
  <p>I'd like the <code>stdout</code> and <code>stderr</code> from <code>script.py</code> to be saved to
  files in addition to displaying on the screen (like using <code>tee</code> and
  shell redirections from a bash shell).</p>
  
  <p>I have two requirements that are difficult to satisfy simultaneously:</p>
  
  <ol>
  <li>Display and capture <code>stdout</code> and <code>stderr</code> in a manner that is
     transparent to <code>script.py</code>.</li>
  <li>Preserve the ability to debug after an exception.</li>
  </ol>
  
  <p>I have not found a way to accomplish (1) that does not break the interactive debugger.  I believe this is because <code>ipython</code> (or <code>ipdb</code>) uses <code>stdout</code> to interact with the user during debugging.  If I were willing to modify <code>script.py</code> this would not be too difficult (e.g. custom logging logic) but I'm hoping to use this very generically like shell redirection.</p>