How can I capture Java compiler errors into a file?

∥☆過路亽.° 提交于 2019-12-21 05:27:11

问题


I compiled a Java program as

javac t1.java > a

in order to redirect the error messages to file a. But a doesn't have the error contents (they still appear in the terminal). The command is executed from Linux command prompt.

The contents of t1.java is as:

class t1 {
    public static void main(String[] args) {
       System.out.printn("Hello World!"); // Display the string.
    }
}

So now there is an error, i.e. println is written as printn.

How can I capture this error message in file a?


回答1:


Try redirecting the stderr:

javac t1.java 2> error_file 



回答2:


> foo implies 1> foo where 1 is the stdout stream.

In bash, if you want to redirect the stderr stream, use 2> foo

The standard Unix fileno's are 0 - stdin, 1 - stdout, 2 - stderr.



来源:https://stackoverflow.com/questions/2665589/how-can-i-capture-java-compiler-errors-into-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!