
1、通过ProcessBuilder进行调度,这种方法比较直观,而且参数的设置也比较方便。
ProcessBuilderpb=newProcessBuilder("./"+RUNNING_SHELL_FILE,param1,
param2,param3);
pb.directory(newFile(SHELL_FILE_DIR));
intrunningStatus=0;
Strings=null;
try{
Processp=pb.start();
try{
runningStatus=p.waitFor();
}catch(InterruptedExceptione){
}
}catch(IOExceptione){
}
if(runningStatus!=0){
}
return;
2、直接通过系统Runtime执行shell,特别是参数方面,必须自己加空格分开。
因为exec会把整个字符串作为shell运行。
p=Runtime.getRuntime().exec(SHELL_FILE_DIR+RUNNING_SHELL_FILE+""+param1+""+param2+""+param3); p.waitFor();
以上就是java调用shell脚本的方法,希望对大家有所帮助。更多Java学习指路:Java基础
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容