cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

logging java console output to disk

jsulak
1-Newbie

logging java console output to disk

Hello Adepters,

Is there any way to save to disk that output that usually goes to the java console? Arbortext help says "If the Java Console is closed, output will be discarded on Windows and sent to stdout on UNIX." Unfortunately, I'm on Windows.

As a practical matter, we use a wrapper function around all of our Java print statements, so I could manually write everything to disk there. But I also want to capture the output from any exceptions that occur, which would require a more general capturing of system.out and system.err, I would think.

Thanks,

-James

3 REPLIES 3
jsulak
1-Newbie
(To:jsulak)

Actually, I just figured out one way to do it. Typing the following into the javascript command line seems to do the trick:

var newOutputStream = new java.io.PrintStream(new java.io.FileOutputStream("c:\\temp\\output.txt"));
java.lang.System.setOut(newOutputStream);

java.lang.System.setErr() looks like it does the same thing for system.err.

-James

Hi James-



You can do this with a little Java code--which you can run through
Javascript if you want to skip the whole compilation phase):



Packages.java.lang.System.setOut(

new Packages.java.io.PrintStream(

new Packages.java.io.FileOutputStream("C:/temp/jstdout.dat")));



Packages.java.lang.System.setErr(

new Packages.java.io.PrintStream(

new Packages.java.io.FileOutputStream("C:/temp/jstderr.dat")));



This will cause standard output to be written to jstdout.dat and
standard error to jstderr.dat.



Hope that helps.



--Clay


jsulak
1-Newbie
(To:jsulak)

Thanks, Clay. It was one of those things where just writing the e-mail helped me figure it out, but it's great to have confirmation from someone who knows more than me.

-James
Top Tags