I am using java Runtime.exec() method to execute bat file,in bat file i have write code that execute jar.This jar contain thread class that pooling infinite time the rabbitmq queue,if message are found then perform operation on that,mean the process will run infinite. i want to kill this process using java code,also i want know that can this method are able to execute shall script on Linux Os.
**Used java code**
String myCMD = "cmd.exe /C start c:\\elasticmgmtservice.bat";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(myCMD);
**used batch file**
cd c:
cd ElasticMgmtService\
java -jar ElasticIndexManagementService.jar config\ElasticIndexManagementService.xml
please help me to solve the problem.
Runtime.exec(...) returns Process
object which consists following methods
you can call destroy() which kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
or you can kill by passing taskkill /PID <process id>
in Runtime.exec(...)
or kill -9 <process id>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With