The redirect() method shown in this post only works for output that is written via the Python sys.stdout handle.
If your code links against C/C++ extensions that have internal printf calls, then you need something lower-level, which can intercept the data at the file handle.
There's a great solution for that on StackOverflow: https://stackoverflow.com/a/22434262/162094