Skip to main content
1-Visitor
April 19, 2010
Question

logging java console output to disk

  • April 19, 2010
  • 3 replies
  • 959 views
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

    jsulak1-VisitorAuthor
    1-Visitor
    April 19, 2010
    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
    18-Opal
    April 19, 2010
    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


    jsulak1-VisitorAuthor
    1-Visitor
    April 19, 2010
    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