How to save java -version return to cmd

Asked

Viewed 354 times

1

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

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

It creates the file but does not save the return in the file. Any other command a ping or ipconfig as for example

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

he saves normally. If anyone knows any alternative, I’d appreciate it.

1 answer

1


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.