Is there any special reason for the results of
java -version going to
For example, this command executed from Windows' prompt line:
java -version > java_version.txt
leaves the file
EDIT: The same happens with the help printed out after executing
java.exe without any parameters.
EDIT: Just out of a sheer curiosity I checked whether it has been always like that and it turned out it actually has.
java -version goes to
stderr in JDK 1.1.8 and also in JDK 1.2.2, however the outputs of
java.exe without any parameters do not.
Is there any special reason for the results of java -version going to stderr?
AFAIK, there is no special reason. It is just how the
java command is implemented.
My brief investigation shows that this is inconsistent with how most Linux commands behave ... everything else I've tried uses stdout. However
-version options are a convention rather than something required by any standard.
What can / should you do?
-versionoutput to stdout without potentially breaking customer scripts. This is highly unlikely1.
1 - Here is evidence of just how unlikely it is: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4380614. Note the "Resolution: Wont Fix" ... and the final comment.
The workaround for this problem is:
java -version 2> java_version.txt