/**
* @author zhangjunyao
* 启动、停止本地程序
*/
public class AppOperationTest {
public static void main(final String[] args) throws IOException {
startExe();//启动程序
// killExe();//关闭程序
}
public static void startExe() {
final Runtime runtime = Runtime.getRuntime();
Process process = null;
try {
process = runtime.exec("C:\\Users\\Administrator\\Desktop\\FeiQ.exe");
} catch (final Exception e) {
System.out.println("Error exec!");
}
}
public static void killExe(){
try {
String cmd = "cmd /c " +"taskkill /f /im \"FeiQ.exe\"";
Runtime rt = Runtime.getRuntime(); // 获取运行时系统
Process proc = rt.exec(cmd); // 执行命令
InputStream stderr = proc.getInputStream(); // 获取输入流
InputStreamReader isr = new InputStreamReader(stderr, "GBK");
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) { // 打印出命令执行的结果
System.out.println(line);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
使用java程序启动,停止本地应用
最新推荐文章于 2023-11-10 10:45:31 发布