Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I capture Java compiler errors into a file?

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?

like image 831
Hulk Avatar asked Dec 23 '22 03:12

Hulk


2 Answers

Try redirecting the stderr:

javac t1.java 2> error_file 
like image 186
codaddict Avatar answered Jan 05 '23 15:01

codaddict


> 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.

like image 20
Alex Budovski Avatar answered Jan 05 '23 15:01

Alex Budovski