How to save return from java -version command in cmd

1

I have a problem saving in .txt the return of the "java -version" command executed in cmd. I'm running as follows:

java -version >> "%temp%/resultado.txt"

It creates the file but does not save the return to the file. Any other ping command or an ipconfig such as

ipconfig /flushdns >> "%temp%/resultado.txt"

it saves normally. If anyone knows of any alternatives, I appreciate it.

    
asked by anonymous 26.05.2017 / 19:19

1 answer

1

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:

    
26.05.2017 / 19:37