2

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
0

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You should refer to the documentation... basically, STDERR is intended to receive error messages (as the name denotes), all other data is usually written to STROUT; but it always depends on the "mood" of the developers...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.