java processbuilder/rt.exec 问题

发布于 2024-09-14 10:55:52 字数 437 浏览 3 评论 0原文

假设我有 2 个单独的 java 应用程序 javaapp1 和 javaapp2。
从 javaapp1 中,我正在执行一个 .bat 文件(它负责启动 javaapp2)。

javaaap1 和 javaapp2 彼此独立。

假设我使用 process.exec 或 processbuilder 来执行此操作。

现在我的问题是:

  1. 如果 exitCode 不为 0,那么在这种情况下它意味着什么。这是否意味着执行批处理文件时出现问题 或者在javaapp2的代码中?或者两者都有?

  2. 是否可以在 javaapp1 中捕获 javaapp2 的错误?如果可以:如何捕获?由于我没有直接调用 javaapp2 的类。

  3. 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:

  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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2024-09-21 10:55:52
  1. 退出代码将是其他 Java 应用程序在 System#exit() 调用。如果您通过 bat 文件执行它,则需要确保它正确地传回。

  2. 您可以让它写入 stdout stderr ,然后分别可以通过 Process#getInputStream()Process#getErrorStream()

  3. 如果它包含正确处理 1) 和 2) 提到的结果的代码,那么可以。

相关文章:

  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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文