How do I get the bash command exit code from a Process run from within Java?

爱⌒轻易说出口 提交于 2019-11-28 13:42:21

Process.waitFor() returns an int That is where the exit code is returned. If you start an unrelated program, won't have a previous exit code which is why it doesn't return anything useful.

You can't use exitValue() reliably because you could call it before the program has finished. You should only call it after calling waitFor() (and it will give the same exit code waitFor() does)

From the Javadoc for exitValue

Throws: IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!