开发者

java processbuilder/rt.exec questions

Lets say I have 2 individual java applications javaapp1 and javaapp2.

from javaapp1, I am executing a .bat file (which is responsible for starting javaapp2).

javaaap1 and javaapp2 are independent to eachother.

Suppose I am doing it with process.exec or processbuilder.

Now my question is:

  1. What does exitCode means in this case if its not 0.Does it mean that something went wrong in executing batch file or in the code of javaapp2? or both?开发者_开发百科

  2. Is it possible to capture errors from javaapp2 in javaapp1?If yes: How? Since i am not calling classes of javaapp2 directly.

  3. Is javaapp2 errors and output are to be handled by javaapp1?


  1. The exitcode will be whatever the other Java application has returned on System#exit() call. If you're executing it through a bat file, you need to ensure that it passes it back correctly.

  2. You can let it write to stdout or stderr, it will then by available by respectively Process#getInputStream() and Process#getErrorStream().

  3. If it contains code to handle the results mentioned by 1) and 2) correctly, then yes.

Related articles:

  • When Runtime#exec() won't - discusses the important traps to know.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜