简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM