This question already has an answer here:
- How To catch python stdout in c++ code 3 answers
Currently I have this setup:
#include <python3.5/Python.h>
#include <boost/python.hpp>
int main()
{
using namespace boost::python;
Py_Initialize();
try
{
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__");
object ignored = exec("print('Hello Python')", main_namespace);
}
catch (error_already_set const&)
{
PyErr_Print();
}
// Py_Finalize();
return 0;
}
When compiled and ran, the above code outputs Hello Python
to the console. Can I instead specify an output stream for python?
Aucun commentaire:
Enregistrer un commentaire