Runtime rn = Runtime.getRuntime();
try {
String path=request.getSession().getServletContext().getRealPath("/service")+ "/startup.exe";
Process pro = rn.exec("cmd /c tasklist |find \"startup.exe\" ");
BufferedReader reader = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String str = reader.readLine();
if(str==null || "".equals(str)){
rn.exec(path);
}
reader.close();
} catch (Exception e) {
request.setAttribute("msg", "打开服务器过程出错!");
}
在Java中运行exe文件,要求:如果该文件已经运行,则不允许打开。
我的Demo:Java运行一个exe文件
最新推荐文章于 2023-12-03 22:32:02 发布