Question: 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 ;)

Answer: 
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.
Based on [this answer](https://stackoverflow.com/a/13389875/18573), I think you should be able to reassign the [processe's stderr](http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#setErr%28java.io.PrintStream%29). You will need another thread that reads from it while the JNI function is executing so that it does not block.