Though the batch file may be terminated, the console (window) the batch file has been running in may be left open, depending on the operating system, the command processor, and how batch file execution was started (from a command prompt or through a shortcut).
taskkill
is a good command for ending a program which is distributed with Windows (I'm assuming you want to stop a DIFFERENT program, not the batch file itself).
It is possible to end programs by process id, executable name, window title, status (i.e. not responding), DLL name, or service name.
Here are some examples based on how you might use this in your batch file:
Force "program.exe" to stop (often the /f "force" flag is needed to force the program to stop, just check whether it is needed for your application by trial and error):
taskkill /f /im program.exe
Stop any non-responsive programs:
taskkill /fi "Status eq NOT RESPONDING"
Stop a program based on its window title (* wildcard is allowed here to match anything):
taskkill /fi "WindowTitle eq Please Login"
taskkill /fi "WindowTitle eq Microsoft*"
You can even use it to stop a program on another computer on your network (although writing the password of an account in a batch file is just not a good idea).
taskkill /s JimsPC /u Jim /p James_007 /im firefox.exe
Another alternative also distributed with Windows is tskill
. Although it doesn't have nearly as many options, the commands are a bit simpler.
EDIT:
I am not sure there is. I would think that closing the cmd window is akin to force-closing
the app i.e. immediate termination with no further notice. This has the behavior of many applications that, when they are asked to force-close
, they actually take a long time to finally terminate. This is because in the OS's efforts to release all resources, some resources (especially certain I/O and/or file resources) don't let go immediately.
IMO, there's nothing Java could even do about it if it wanted to. A force-close happens at the OS level, at which point it releases the memory, file and I/O handles in use, etc. Java does not (nor does any other program) have control over a force-close. At this point, the OS is taking charge.
Someone please correct me if I'm wrong.