我有一个jar说test.jar有TestJar作为它的主类,一个shell脚本jar_executor.sh和一个java文件.如果我们传递1作为参数,我的test.jar将返回1,如果我们传递任何其他值,则返回2.我的shell脚本正在执行test.jar,如下所示
#!/usr/bin/ksh
java TestJar 1 -cp test.jar
return_code=$?
exit $return_code
Run Code Online (Sandbox Code Playgroud)
在java文件中,我正在创建一个进程并执行shell脚本,并使用以下代码获取其exitvalue
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(sh jar_executor.sh);
int exitVal = process.waitFor();
System.out.println(exitVal);
Run Code Online (Sandbox Code Playgroud)
这个exitVal变量应该按照我们传递的参数打印1或2,但每次打印255.如果我echo $return_code
在shell脚本中使用,那么我得到正确的值.请帮助我为什么我得到255的价值exit
.提前致谢!!!