redirecting standard error

Hello

I've got:

legacy c code that writes to standard error

JNI c code that calls the legacy stuff

java code that calls the JNI c code

I want to capture standard error and have it available in the java code AND I don't want to redirect stderr to a file and then read that back in.

I tried:

ByteArrayOutputStream capturedStderr;

PrintStream stderrPS;

capturedStderr = new ByteArrayOutputStream();

stderrPS=new PrintStream(capturedStderr);

System.setErr(stderrPS);

hoping that capturedStderr.toString() would give me whatever was written to stderr.

It didn't ;-(

Any suggestions?

Thanks

Mark

[709 byte] By [juszczec] at [2007-9-26 5:01:00]
# 1

When you do System.setErr() all it does is reset err.

What you need to do is reset stderr and I don't believe that is possible solely in java.

I believe you can write JNI to redirect stderr in C to a new file. Then you use that file descriptor to create a new stream in java which is used to call System.setErr().

jschell at 2007-6-29 18:57:31 > top of Java-index,Java HotSpot Virtual Machine,Specifications...