Python ctypes dll stdout

I am calling a DLL function from python using ctypes and just want to grab stdout from a dll call. There are many printfs that I would like to redirect without changing the dll code itself.

How can i do this?

+2
source share
1 answer

Sounds like you need to make a wrapper . Try something like this:

char* CallSomeFunc()
{
    ostrstream ostr;
    cout.rdbuf(ostr.rdbuf());
    SomeFunc();
    char* s = ostr.str();
    return s;
}

You really need to do something different with this string, and not return it; I will leave this part to you. The line pointer becomes invalid as soon as it returns, but you can make a fairly simple allocation if you free the memory after it is returned.

+1
source

All Articles