I am not able to write the output of java -version from a batch file to a text file using:
java -version>tmp.txt
However, the following works (that is, the data is written to the text file):
java>tmp.txt
The command line java -version returns the output data at the STDERR stream (rather than STDOUT). The redirection operator > uses the stream handle 1 by default, which is the STDOUT stream. To read from the STDERR stream, you need to state the respective handle 2 explicitly:
java -version 2>tmp.txt
The command line java behaves as expected, because it returns the output at STDOUT.
Reference this external resource for details: Redirection.