int exitCode;
StringBuilder result = new StringBuilder();
try {
// 创建一个ProcessBuilder对象
ProcessBuilder processBuilder = new ProcessBuilder("/usr/xxx/sss.sh");
// 将参数添加到进程构建器中,没有参数也可以不写
processBuilder.command().add("1");
// 启动这个shell脚本进程
process = processBuilder.start();
// 创建一个BufferedReader对象,用于从process的输入流中读取数据(即shell脚本的输出)
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
result.append(line).append("\n");
}
exitCode = process.waitFor();
} catch (IOException | InterruptedException e) {
}
if (exitCode != 0) {
log.error("执行脚本失败");
return ;
}