Redirect the output of System.err.println to a file without code change

830 Views Asked by At

I have an existing jar file that contains a class I am execution from a batch file as shown below.

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 

The class contains lot of System.out and System.err. The System.out is going to the log file mentioned as redirection but the error message is still coming to the console.

How can I redirect System.err to the same log file? I am not in a position to change the code of the classes in the jar file.

1

There are 1 best solutions below

1
Elliott Frisch On BEST ANSWER

You redirect stderr, like

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 2>> ERR_LOG_FILE_name

To use the same log file that would be

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 2>&1