Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

stdout redirection in Native Code

843829May 19 2004 — edited Sep 13 2006
I'm developing an application on Windows with Java and some code written in C. I have a C code that prints to stdout with printfs. I call this code thru JNI. I want to read from Java the output generated with the printfs, because it must be processed and transmitted. I know I can redirect stdout to a file and then make Java open that file and process it, but i'm searching for a better solution.

My question is how can i redirect both System.out and stdout to the same location (file, TextArea, Stream, ...)? I have seen other threads in the forum asking something similar, but they are all inconcluse.

I have seen solutions with the use of Process (or native CreateProcess) and i'm asking if there is any solution without the use of other Threads. I see an approach (searching jni question stdout in google) that make a pipe between the C code and Java (between Threads) on Unix systems, but when I do it on Windows, when i read from the pipe i obtained only scratch.

I hope a have explained me clearly.

Thanks all the people how makes the Community work!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2006
Added on May 19 2004
3 comments
529 views