title: In python, how to capture the stdout from a c++ shared library to a variable
body: <p>For some other reasons, the c++ shared library I used outputs some texts to standard output. In python, I want to capture the output and <strong>save to a variable</strong>. There are many similar questions about redirect the stdout, but not work in my code. </p>
  
  <p>Example: <a href="https://stackoverflow.com/questions/4178614/suppressing-output-of-module-calling-outside-library">Suppressing output of module calling outside library</a></p>
  
  <pre><code>1 import sys
  2 import cStringIO
  3 save_stdout = sys.stdout
  4 sys.stdout = cStringIO.StringIO()
  5 func()
  6 sys.stdout = save_stdout
  </code></pre>
  
  <p>In line 5, <strong>func()</strong> will call the shared library, the texts generated by shared library still output to console! If change <strong>func() to print "hello"</strong>, it works!</p>
  
  <p>My problem is:</p>
  
  <ol>
  <li>how to capture  stdout of the c++ shared library <strong>to a variable</strong>?</li>
  <li>Why using StringIO, can't capture the outputs from shared library?</li>
  </ol>