I am running some java apps and I need to shutdown/close all apps gracefully from windows bat script.
So my question is:
How to invoke shutdown hook by windows bat script and gracefully shutdown java program.
Any suggestion is appreciated. Thanks in advance.
Take a look at the addShutdownHook method in the Runtime
class.
Runtime.getRuntime().addShutdownHook(...);
UPDATE: As per comment below, there is a command TASKKILL in the windows shell that is similar to the *nix kill command. For instance TASKKILL /IM java.exe
would terminate all java processes. TASKLIST
can be used to find all running processes. Using this in conjunction with a shutdownhook should give you the graceful possibilites required.
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