java - Why Process destroy cannot work when exec bat but not exe -


process p = runtime.getruntime().exec(new string[] { "c:/work/bat/consoleapplication1.exe" }); thread.sleep(4000); p.destroy(); int res = p.waitfor(); system.out.println("res" + res); 

this print res1 , jvm stoped @ 1 time, if :

process p = runtime.getruntime().exec(new string[] { "c:/work/bat/exe.bat" }); 

this print res1 after 4s jvm not stopped @ 1 time. jvm stop after more 6s.

this exe.bat

 c:\work\bat\consoleapplication1.exe 

this consoleapplication1.exe:

int _tmain(int argc, _tchar* argv[]) { int a=0; while(a<100){     sleep(100);     cout<<a++ <<endl; } return 0; } 

so, how can stop bat file exe file?

try kill process. find process id , use taskkill command.

runtime rt = runtime.getruntime(); rt.exec("taskkill " +<your process id>); 

but works in windows. linux use -

rt.exec("kill -9 " +<your process id>); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -