title: Capturing print output from shared library called from python with ctypes module
body: <p>I am working with a shared library that is being called through the ctypes module.  I would like to redirect the stdout associated with this module to a variable or a file that I can access in my program.  However ctypes uses a separate stdout from sys.stdout. </p>
  
  <p>I'll demonstrate the problem I am having with libc.  If anyone is copying and pasting the code they might have to change the filename on line 2.</p>
  
  <pre><code>import ctypes
  libc = ctypes.CDLL('libc.so.6')
  
  from cStringIO import StringIO
  import sys
  oldStdOut = sys.stdout
  sys.stdout = myStdOut = StringIO()
  
  print 'This text gets captured by myStdOut'
  libc.printf('This text fails to be captured by myStdOut\n')
  
  sys.stdout = oldStdOut
  myStdOut.getvalue()
  </code></pre>
  
  <p>Is there any way I can capture the stdout that is associated with the ctypes loaded shared library?</p>