java processbuilder/rt.exec 问题
假设我有 2 个单独的 java 应用程序 javaapp1 和 javaapp2。
从 javaapp1 中,我正在执行一个 .bat 文件(它负责启动 javaapp2)。
javaaap1 和 javaapp2 彼此独立。
假设我使用 process.exec 或 processbuilder 来执行此操作。
现在我的问题是:
如果 exitCode 不为 0,那么在这种情况下它意味着什么。这是否意味着执行批处理文件时出现问题 或者在javaapp2的代码中?或者两者都有?
是否可以在 javaapp1 中捕获 javaapp2 的错误?如果可以:如何捕获?由于我没有直接调用 javaapp2 的类。
javaapp2 错误和输出是否由 javaapp1 处理?
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:
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?Is it possible to capture errors from javaapp2 in javaapp1?If yes: How? Since i am not calling classes of javaapp2 directly.
Is javaapp2 errors and output are to be handled by javaapp1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
退出代码将是其他 Java 应用程序在
System#exit()
调用。如果您通过bat
文件执行它,则需要确保它正确地传回。您可以让它写入 stdout 或 stderr ,然后分别可以通过
Process#getInputStream()
和Process#getErrorStream()
。如果它包含正确处理 1) 和 2) 提到的结果的代码,那么可以。
相关文章:
The exitcode will be whatever the other Java application has returned on
System#exit()
call. If you're executing it through abat
file, you need to ensure that it passes it back correctly.You can let it write to stdout or stderr, it will then by available by respectively
Process#getInputStream()
andProcess#getErrorStream()
.If it contains code to handle the results mentioned by 1) and 2) correctly, then yes.
Related articles: