/**
* 解決了 參數中包含 空格和腳本沒有執行權限的問題
* @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("\n");
}
//執行結果
String result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}