停止使用批处理文件启动的进程

| 我使用以下命令从我的Java代码启动批处理文件
Runtime.getRuntime().exec(\"cmd /c start myFile.bat\");
依次启动一个应用程序,现在我想停止该批处理文件启动的应用程序,如何实现它。可能存在相同应用程序的多个实例已经在运行的情况,但是我想停止此批处理文件启动的一个实例。有可能,我的服务器在Windows上。 由于这是游戏应用程序,需要环境也尝试过
Runtime rt = Runtime.getRuntime() ;
            Process p = rt.exec(\"C:/Valve/HLServer/hlds.exe +maxplayers 32 -game cstrike -console +port 27015 -nojoy -noipx -heapsize 250000 +map cs_italy +servercfgfile server.cfg +lservercfgfile +mapcyclefile mapcycle.txt +motdfile motd.txt +logsdir logs -zone 2048\",null,  new File(\"C:/Valve/HLServer\")) ;
但仍然没有运气:(     
已邀请:
this will kill the command prompt not the method launched from that command prompt.
他是对的 做这个
 Process process = Runtime.getRuntime ().exec (\"/folder/exec.exe\") //your application
 p.destroy();
    
getRuntime()
方法返回
Process
类的对象,使用ѭ5you对象,可以对Process对象调用
destroy()
方法以杀死进程
Process p = Runtime.getRuntime().exec(\"cmd /c start myFile.bat\"); //starts the process
p.destroy();    //kills the process
    

要回复问题请先登录注册