When redirecting output from an application using the >
symbol, error messages will still print on the screen. This is because error messages are often sent to the default error stream instead of the standard outbound flow.
The command outputs are sent by two separate chains. Normal output is sent by the STDOUT standard and error messages are sent by STDERR .
When you redirect console output using the >
symbol, you are only redirecting STDOUT . In order to redirect STDERR you have to specify 2>
for the redirect symbol. This selects the second output current that is stderr .
Java returns this output as an error so you should use this command:
java -version 2> JavaVersion.txt
It is still possible to insert the output at the end of the file instead of overwriting the content using two >
symbols as follows.
java -version 2>> JavaVersion.txt
Source: