开发者

Stop a process launched using batch file

i launch a batch file from my java code using

Runtime.getRuntime().exec("cmd /c start myFile.bat");

which in turn launches an application, now i want to stop the application been launched by this batch file, how to achieve it. there may be the case that the same multiple instance of same application are already running, but i want to stop the one being launched by this batch file. is it poss开发者_如何转开发ible, my server is on windows.

since this was game application and need the enviroment also tried

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")) ;

but still no luck :(


getRuntime() method returns Process class's object and using the Process object you can call destroy() method on the Process object to kill the process

Process p = Runtime.getRuntime().exec("cmd /c start myFile.bat"); //starts the process
p.destroy();    //kills the process


this will kill the command prompt not the method launched from that command prompt.

he is right

do this

 Process process = Runtime.getRuntime ().exec ("/folder/exec.exe") //your application
 p.destroy();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜