Redirect stdout/stderr from JNI native code
Hi,
I have some legacy code, that I need to capture the stdout (printf and cout, etc).
Is there any way in Java to capture them?
I tried to use
System.setOut(new PrintStream(new BufferedOutputStream(
new FileOutputStream("output.dat"))));
but it wouldn't catch them.
Is there any way to do this? Have spent hrs searching over the web,but no good solution.
Any help is appreciated.
Thanks.
Stan
[469 byte] By [
zzzwyxha] at [2007-10-3 1:27:35]

Assuming that you're kicking off a legacy application, as opposed to calling a legacy DLL via JNI.....
Runtime.exec() returns a Process object.
In there, there's the following functions
abstract InputStream getErrorStream()
abstract InputStream getInputStream()
abstract OutputStream getOutputStream()
regards,
Owen
At first glance: create new java subprocess for calling this native method only and capture subprocess' output.Or create starter process, start your process, capture output of your process and then communicate between starter and your process.I'll think for better