Closed utkonos closed 2 years ago
The problem with that recipe for redirecting stdout/stderr from ctypes is that it uses sys.stdout.close()
which conflicts with Jupyter. It would work in standard Python scripts.
It's possible to disable all output by e scr.prompt=false
. I'm not sure whether it's something you would like.
I found a fix!
The following is an elegant context manager for doing exactly what I need: https://pypi.org/project/wurlitzer/
It is a work of art.
I am having trouble capturing stderr when using the Python bindings. I would like to capture the stderr output to a variable, but if that is not possible, at least make the calls quiet. I know how to do this using
r2pipe
with the-2
flag.How can one implement the equivalent of the
-2
flag using the Python bindings here?Also, it is possible to capture this output, what is the best way to do that?
I have tried using
contextlib.redirect_stderr()
and it fails.The problem appears to be that the output is a c-level stream. I tried the following, but it also doesn't work properly: https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/