How do I pipe the Java console output to a file?

后端 未结 5 1570
误落风尘
误落风尘 2020-12-08 21:17

I found a bug in an application that completely freezes the JVM. The produced stacktrace would provide valuable information for the developers and I would like to retrieve i

5条回答
  •  生来不讨喜
    2020-12-08 21:55

    (If you can modify the code) you can set the System.out field to a different value:

    System.setOut(new PrintStream(new FileOutputStream(fileName)));
    

    If you are running a script (invoking the program via java) from Unix you could do:

    /path/to/script.sh >& path/to/output.log
    

提交回复
热议问题