How to catch CDLL stdout/stderr output?
#1
Hello everyone,

I'm trying to run a shared library from plugin code. 
I do see that code runs fine, but I cannot see/catch stdout/stderr.

My python code is simple:
python:

lib = ctypes.cdll.LoadLibrary(library_path)
library_thread = threading.Thread(target=start_library, args=[lib])
library_thread.start()

def start_library(lib):
        log.info("Calling start!")
        lib.start()

Library is writing to Stdout. It works (I do verify it), and when I run same code through Subprocess with `proc.stdout.readline()` it properly catches the output, but I want to run it now as a shared library.
I was googling and trying different approaches, but since `sys.stdout` is a custom code, that logs everything, I can't get `sys.stdout.fileno()`.

As far as I understand, on Linux it should not be an issue (have not tried yet), but I first try to run on Windows.

Would appreciate any advice/help!
Reply
#2
Right after creating this topic I realized that I can redirect library output to a temporary file, located inside of Kodi temporary folder (from library side). 
And then just stream that file into xbmc logger. 
Not a perfect solution, but it would work everywhere in the same manner.
Reply

Logout Mark Read Team Forum Stats Members Help
How to catch CDLL stdout/stderr output?0