我正在尝试使用 ProcessBuilder 执行带有命令行参数的 shell 脚本,这个 shell 脚本又调用了另外两个使用这个参数的 shell 脚本。第一个 shell 脚本运行良好,但是当第二个脚本启动时,它返回退出代码 1。
Java 程序中的 ProcessBuilder 片段:
//scenario - A string that holds a numerical value like 1 or 2 etc
String[] command2 = {"/bin/bash", "<path to shell script>/runTemporaryTestSuite.sh", scenario};
ProcessBuilder pb2 = new ProcessBuilder(command2);
Process p2 = pb2.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line;
//print - is an object ref of response.getWriter() //
print.println("Output of running "+Arrays.toString(command2)+" is: ");
while ((line = br.readLine()) != null) {
print.println(line);
}
try {
int exitValue = p2.waitFor();
print.println("<br><br>Exit Value of p2 is " + exitValue);
} catch (InterruptedException e) {
e.printStackTrace();
}
runTemporaryTestSuite.sh
#!/bin/bash
sh <path to script>/clearRegressionResult.sh (This runs fine)
sh <path to script>/startRegression.sh $1 (This is where the issue occurs)
startRegression.sh 看起来像:
SUITE_PATH="./"
java -DconfigPath=${SUITE_PATH}/config.xml -Dscenario=$1 -Dauto=true -jar test.jar
我的输出:运行 [/bin/bash, /runTemporaryTestSuite.sh, 29] 的输出是:p2 的退出值是 1
非常感谢解决此问题的任何帮助。