使用 java Runtime exec 调用外部进程时退出代码 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6494095/
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
Exit code 1 while calling an external process using java Runtime exec
提问by bala
I'm using apache commons exec for creating an external java process, which returns an exit code 1 occasionally. When I looked into the code of commons exec the issues doesn't seem to be related to apache commons exec rather to do with Runtime exec on java.
我正在使用 apache commons exec 创建一个外部 java 进程,它偶尔会返回退出代码 1。当我查看 commons exec 的代码时,问题似乎与 apache commons exec 无关,而与 java 上的 Runtime exec 有关。
Here, I'm running a multithreading program which creates these processes. And I have tested the code by passing an idfier to external process to identify if the process got created by failed during processing. But for those threads which are failing while invoking the exex command doesn't seems be invoking the external java process as I don't find the failed process idfier in the log.
在这里,我正在运行一个创建这些进程的多线程程序。我已经通过将 idfier 传递给外部进程来测试代码,以确定进程是否在处理过程中失败。但是对于那些在调用 exex 命令时失败的线程似乎没有调用外部 java 进程,因为我没有在日志中找到失败的进程标识符。
Any suggestions on what could be the potential cause for this would be very much appreciated.
任何关于可能导致这种情况的潜在原因的建议将不胜感激。
回答by THelper
Commons exec just returns you the exit code of the external process whenit's finished. Usually exit code 1 means "exited with some error". The exact meaning of the code will vary for each application. If you are lucky, the exit codes of your external java process have been defined in it's API or other documentation so you can look it up. If not, try to find the source code or contact the makers of the code.
Commons exec 只是在完成时返回外部进程的退出代码。通常退出代码 1 表示“退出时出现一些错误”。代码的确切含义因应用程序而异。如果幸运的话,外部 java 进程的退出代码已在其 API 或其他文档中定义,因此您可以查找它。如果没有,请尝试查找源代码或联系代码的制作者。