I have a big program developed in C, and most functions have several
fprintf(stderr, "message")
lines.
But right now I need to use those functions in a Java program. So, I implement a JNI interface to communicate between Java and C. Everything is ok, Java and C can communicate, but now I want to capture the several stderr's of C in Java... How can I do that?
Cheers ;)
Out of my experience exactly with the same problem, i can tell that JNI bridge has very strange opinion on the importance of what's going out of JNI through standard streams. Generally it does heavy caching, spilling in unpredictable chunks and timing, and we didn't figure out how to force flushing.
We ended up with mass regex replacement of *printf()
statements with logging to a file, done altogether on C side. Tailing the resulting logfile was way more reliable than any attempts to convince JVM that you really need the logging when C layer says so, not when JVM makes its mind on the buffers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With