java 跑cmd,直接使用:
String cmd = "sh xxx.sh param1 param2";
Process process = Runtime.getRuntime().exec(cmd);
// 需要把输出拿一下,不然一闪就过去了。
try (InputStream inputStream = process.getInputStream()) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
//System.out.println(line);
}
}
// 加一个 waitFor 等待cmd 返回.
if (process.waitFor() != 0) {
System.out.println("process 已经结束:" + guid);
}