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

2019-01-17 11:41发布

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 it from the Java console. When the JVM crashes, the console is frozen and I cannot copy the contained text anymore.

Is there way to pipe the Java console directly to a file or some other means of accessing the console output of a Java application?

Update: I forgot to mention, without changing the code. I am a manual tester.

Update 2: This is under Windows XP and it's actually a web start application. Piping the output of

javaws jnlp-url
does not work (empty file).

5条回答
相关推荐>>
2楼-- · 2019-01-17 11:55

A frozen console probably means a deadlock (it could also mean repeated throwing of an exception). You can get a stack dump using jstack. jps may make finding the process easier.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-17 12:00

Actually one can activate tracing in the Java Control Panel. This will pipe anything that ends up in the Java console in a tracing file.

The log files will end up in:

  • <user.home>/.java/deployment/log on Unix/Linux
  • <User Application Data Folder>\Sun\Java\Deployment\log on Windows
  • /~/Library/Caches/Java/log on OS X
查看更多
趁早两清
4楼-- · 2019-01-17 12:05

try this guide it works for me. it also guides you that how you can set "System.setOut(fileStream);", "System.setErr(fileStream);"

查看更多
冷血范
5楼-- · 2019-01-17 12:06

(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
查看更多
Summer. ? 凉城
6楼-- · 2019-01-17 12:08

In Mac 10.8.2 logs could be found at /Users/<userName>/Library/Application Support/Oracle/Java/Deployment/log/.

Before you have to enable logging from Java Control Panel. Option "Enable logging" is at tab "Advanced". Java Control Panel could be started from "System preferences".

查看更多
登录 后发表回答