Cannot launch shell script with arguments using Java ProcessBuilder

与世无争的帅哥 提交于 2019-12-05 22:29:39

In think the problem is not that you cannot launch shell script with arguments, I was curious and I did a test

public class Main {

public static void main(String[] args) throws IOException {
    String[] command = {"/bin/bash", "test.sh", "Argument1"};
    ProcessBuilder p = new ProcessBuilder(command);
    Process p2 = p.start();
    BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream()));
    String line;

    System.out.println("Output of running " + command + " is: ");
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
}

here is the test.sh script

echo Hello im the script, here your args $@

Here the output

Output of running [Ljava.lang.String;@604e9f7f is: 
Hello im the script, here your args Argument1

What I think is just that your startRegression.sh exit with a non-0 status (aka it failed somewhere) and it have repercussion, runTemporaryTestSuite.sh will also exit with a non-zero status, and so on hence the message : Exit Value of p2 is 1

What I see right now,

SUITE_PATH="./" java -DconfigPath=${SUITE_PATH}/config.xml [..] the configPath will be .//config.xml so maybe you have a plain file not found issue? I might be wrong, hope it helped

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