windows下java怎样调用shell脚本文件

如题所述

第1个回答  2016-08-06
// 用法:Runtime.getRuntime().exec("命令");

String shpath="/test/test.sh"; //程序路径
Process process =null;
String command1 = “chmod 777 ” + shpath;
try {
Runtime.getRuntime().exec(command1 ).waitFor();
} catch (IOException e1) {
e1.printStackTrace();
}catch (InterruptedException e) {
e.printStackTrace();
}

String var="201102"; /参数
String command2 = “/bin/sh ” + shpath + ” ” + var;
Runtime.getRuntime().exec(command2).waitFor();本回答被提问者采纳
相似回答