Runtime.getRuntime().exec("这里是cmd命令")
关闭 wps.exe 进程,以下是完整写法,如果只执行
exec()
方法有时会卡住
@Test
public void closeProgress() {
try {
Process process = Runtime.getRuntime().exec("taskkill /f /im wps.exe");
InputStream errorStream = process.getErrorStream();
InputStreamReader reader = new InputStreamReader(errorStream);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
process.waitFor(); // 等待进程结束
} catch (Exception e) {
e.printStackTrace();
}
}