I am using a C library from my C++ code which provides pybind11 bindings. The C library (which I cannot change) is using fprintf like outputs. I want to display these messages when I use the pybind11 bindings in python.
fprintf
In a note in the pybind11 documentation regarding stream redirection https://pybind11.readthedocs.io/en/stable/advanced/pycpp/utilities.html#capturing-standard-output-from-ostream it is mentioned that this is not working for fprintf like output and one should redirect the streams in C.
I found this https://stackoverflow.com/a/11110451/9759769 for redirecting streams to files, but I could not manage to adopt this to get it working with pybind11.
How can I setup the redirection to get it work with pybind11?
2.1m questions
2.1m answers
60 comments
57.0k users