title: pybind11 Redirect python sys.stdout to c++ from print()
body: <p>I have a c++ program with a pybind11 embedded python interpreter, executing the following python file, it prints directly to <code>std::cout</code></p>
  
  <pre><code># test.py
  print("text")
  </code></pre>
  
  <p>The c++ program executing the file:</p>
  
  <pre><code>#include &lt;pybind11/embed.h&gt;
  
  namespace py = pybind11;
  
  int main() {
      py::scoped_interpreter guard{};
      py::eval_file("test.py");
  }
  </code></pre>
  
  <p>Other solutions I found required modifying the python file - how can I redirect python sys.stdout to c++ as a std::string <strong>without</strong> modifying the python code using only the print() statement?</p>