When redirecting an application output using the symbol >
, Error messages will still print on the screen. This is because error messages are often sent to the standard error stream instead of the standard output stream.
Command outputs are sent by two separate chains. Normal output is sent by default STDOUT and error messages are sent by STDERR.
When you redirect the console output using the symbol >
, you are just 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
There is still the possibility 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: https://support.microsoft.com/pt-br/help/110930/redirecting-error-messages-from-command-prompt-stderr-stdout
It worked, thank you!
– Andre Hoffmann