title: Redirecting FORTRAN (called via F2PY) output in Python
body: <p>I'm trying to figure out how to redirect output from some FORTRAN code for which I've generated a Python interface by using F2PY. I've tried:</p>
  
  <pre><code>from fortran_code import fortran_function
  stdout_holder = sys.stdout
  stderr_holder = sys.stderr
  sys.stdout = file("/dev/null","w")
  fortran_function()
  sys.stdout.close()
  sys.stderr.close()
  sys.stdout = stdout_holder
  sys.stderr = stderr_holder
  </code></pre>
  
  <p>This is the de facto method of redirecting output in Python, but it doesn't seem to work in this case (i.e., the output is displayed anyway).</p>
  
  <p>I did find <a href="http://cens.ioc.ee/pipermail/f2py-users/2002-November/000352.html" rel="noreferrer">a mailing list post from 2002</a> saying that "It is possible to read messages from pts devices, e.g. ttysnoop does this". Information on ttysnoop seems to be pretty difficult to find online (I don't think it's been updated in quite a few years; for example, <a href="http://www.linuxhelp.net/guides/ttysnoop/" rel="noreferrer">the first result on Google for "ttysnoop"</a> has only dead links to tarballs, RPMs, and .deb's), and <a href="http://macosx.forked.net/bbarchive/forum5/000008.html" rel="noreferrer">this request for a port to OS X</a> received the response "No luck, it requires some linux specific utmp functions which I can't create."</p>
  
  <p>I'm open to any suggestions on how to redirect the output (it doesn't have to use ttysnoop).</p>
  
  <p>Thanks!</p>