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]
# 1

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

omcgoverna at 2007-7-14 18:25:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Doh.... just read your subject line.... not sure about JNI DLL's....
omcgoverna at 2007-7-14 18:25:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
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
Michael.Nazarov@sun.coma at 2007-7-14 18:25:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Any thoughts on a better solution?Thanks,josef
Kratza at 2007-7-14 18:25:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
Not yet, still thinking ;)I've tried to redirect standart output using native WinAPI functionality without success unfortunately.
Michael.Nazarov@sun.coma at 2007-7-14 18:25:10 > top of Java-index,Java HotSpot Virtual Machine,Specifications...