You'll need to redirect the cout
stream to where Java can read it. You might use a circular buffer with producer/consumer pointers, a callback to Java with the most recent data, or any other method common to inter-process communication. It'll probably be easier to redirect the stream in native code to test, but there's no reason you couldn't translate that native code into JNA calls.
See Rerouting stdin and stdout from C for one method of redirecting stdout
. If you dump to a file, you can have Java read from the file. JNA is perfectly capable of calling freemen
.
You may need to look around to find the actual value of stdout
; look at your system's <stdio.h>
file for its definition. On OSX, it's a global symbol called __stdout
of type FILE*
. On other systems it's the address of an element within a global array of FILE
structs.