executing two commands with process builder

那年仲夏 提交于 2019-12-02 07:10:24

This is normal: two commands mean two processes. You need two ProcessBuilders, and check the return value of the first process before executing the second one.

This syntax:

new ProcessBuilder("javac","Mocha.java","&&","java","Mocha");

does not work. && is a logical shell operator, the javac command does not understand it. Do your processing logic in Java directly instead:

if (p1.waitFor() == 0) // compile succeeded
    // initiate second process

The syntax mentioned works with shell, not with java ProcessBuilder.

Option one is to launch shell and execute shell command. Another is to invoke to ProcessBuilder two times. One for javac another for java

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