JAVA 中 process.exitValue() 的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21479974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Values of process.exitValue() in JAVA
提问by mustafa
This question is about the values of process.exitValue().
这个问题是关于process.exitValue()的值。
If process.exitValue()=0its ok, if it's -1something is wrong, but if it's something else, what does it mean? For instance i am taking 6. That is the code i use:
如果process.exitValue()= 0 没问题,如果它是-1 有什么问题,但如果是别的什么是什么意思?例如,我正在服用6。那是我使用的代码:
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
Integer result = process.exitValue();
Edit:if process hangs, than process.exitValue()= 6
编辑:如果进程挂起,比process.exitValue()= 6
回答by Jon Skeet
That's up to the process in question. Even the "0 means success" is a convention more than anything else - although it's a verycommon one.
这取决于所讨论的过程。即使是“0 意味着成功”也比其他任何东西都重要——尽管它是一个非常常见的约定。
In general I would assume that any non-zero value is an error of some description; look at the documentation for whatever process you're executing for the meaning of specific exit values. If you don't know as the developer what process you're executing (e.g. it's user-specified) then there's no general way of interpreting a non-zero exit code other than "failure".
一般来说,我会假设任何非零值都是某种描述的错误;查看您正在执行的任何进程的文档,了解特定退出值的含义。如果您作为开发人员不知道您正在执行什么进程(例如它是用户指定的),那么除了“失败”之外,没有解释非零退出代码的通用方法。
回答by daark
it depends entirely on what the command is doing see the documentation http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html#exitValue()
这完全取决于命令在做什么,请参阅文档http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html#exitValue()