/**
* 解决了 参数中包含 空格和脚本没有执行权限的问题
* @param scriptPath 脚本路径
* @param para 参数数组
*/
private void execShell(String scriptPath) {
try {
//解决脚本没有执行权限
ProcessBuilder builder = new ProcessBuilder("/bin/chmod", "755",scriptPath);
Process process = builder.start();
process.waitFor();
Process ps = Runtime.getRuntime().exec(scriptPath);
ps.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("
");
}
//执行结果
String result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}