How can I capture Java compiler errors in a file?

I compiled a Java program as

javac t1.java > a 

to redirect error messages to file a . But a does not contain the contents of the error (they are still displayed in the terminal). The command is executed from the Linux command line.

The contents of t1.java is:

 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 written as printn .

How can I capture this error message in file a ?

+4
source share
2 answers

Try redirecting stderr :

 javac t1.java 2> error_file 
+8
source

> 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 file is 0 - stdin, 1 - stdout, 2 - stderr.

+2
source

Source: https://habr.com/ru/post/1307321/


All Articles