为什么'java -version'会转到stderr? [英] Why does 'java -version' go to stderr?

查看:171
本文介绍了为什么'java -version'会转到stderr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java -version 的结果是否有任何特殊原因转到 stderr

Is there any special reason for the results of java -version going to stderr?

例如,此命令从Windows'提示行执行:

For example, this command executed from Windows' prompt line:

java -version > java_version.txt

保留文件 java_version.txt 空。

编辑:在没有任何参数的情况下执行 java.exe 后打印出来的帮助也是如此。

The same happens with the help printed out after executing java.exe without any parameters.

编辑:出于纯粹的好奇心,我检查了它是否总是那样,事实证明它确实存在。 java -version 在JDK 1.1.8和JDK 1.2.2中转到 stderr ,但输出 java.exe 没有任何参数没有。

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.

推荐答案


java -version的结果是否有任何特殊原因要求stderr?

Is there any special reason for the results of java -version going to stderr?

AFAIK,没有特殊原因。这就是 java 命令是如何实现的。可能一直回到Java 1.0,虽然验证它是非常困难的。

AFAIK, there is no special reason. It is just how the java command was / is implemented. Probably all the way back to Java 1.0, though it would be very difficult to verify that.

我的简短调查表明这种行为不一致大多数Linux命令的行为......我尝试过的其他一切都使用stdout来获取版本信息。 (毕竟,版本信息不是错误输出。)

My brief investigation shows that this behavior is inconsistent with how most Linux commands behave ... everything else I've tried uses stdout for version information. (After all, the version information is not "error" output.)

但请注意 - 版本 / -version 选项是一种约定,而不是任何正式标准所要求的。 ( GNU编码标准规定命令应实现 - version 并且该版本信息应该写入标准输出。但是POSIX标准没有提到这一点,也没有提到LSB标准。)

Note however --version / -version options are a convention rather than something required by any formal standard. (The GNU coding standards state that commands should implement --version and that version info should be written to standard output. But POSIX standards don't mention this, nor do the LSB standards.)

你能做什么/应该做什么?

What can / should you do?


  • 应该很容易捕获在shell脚本或批处理文件中使用stderr而不是stdout。

  • 这样做不应该有任何风险。 Oracle无法更改Java工具链以将 -version 输出发送到stdout,而不会破坏客户脚本。这种情况极不可能 1

  • It should be easy to capture stderr instead of stdout in your shell script or batch file.
  • There shouldn't be any risk in doing this. Oracle cannot change the Java tool chains to send -version output to stdout without potentially breaking customer scripts. This is highly unlikely1.

1 - 这里有证据表明它是多么不可能: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id = 4380614 。请注意解决方案:不会修复......以及最终评论。

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.

这篇关于为什么'java -version'会转到stderr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆