1

I have started a process execution in my Java code

pro=Runtime.getRuntime().exec(rootDirectory+"abc.exe", null, new File(rootDirectory));

If I forcibly terminate the Java code running in the middle, this exe file should also terminate. But I seen this exe still running background.

How to auto-terminate this exe if I manually terminate the Java code running?
I tried this: The above code is in try block. Written this code in catch: pro.destroy();: didn't work.
Kept in finally block: didn't work. It's still running background. Please help.

Beso
  • 1,176
  • 5
  • 12
  • 26
  • The point is: putting a try catch around that code ... does nothing that matters in your context. Your code creates another process, and what you need to do: when your java process is told to shutdown, **then** you need to `destroy()` on the process object. And that is what the link you got is about. – GhostCat Dec 17 '21 at 13:52
  • Hey Thanks. This approach looks good. Is there any way to determine: to check "java process is told to shutdown" – sushmitha chavan Chavan Dec 20 '21 at 15:03
  • Hint: read carefully what is shown to you. Like that box that says: *This question already has answers here: Handling abnormal Java program exits* Thats a link there. Click it, read it carefully, when in doubt, pick up the terms, and put them into a search engine. – GhostCat Dec 20 '21 at 18:10

0 Answers0