Scenario was i started the command prompt manually. Then i need to close the Command prompt automatically using Java. How i can close the command prompt using java. Any one can help me
Use the following code:
class CmdKill
{
public static void main(String args[])
{
try {
Runtime.getRuntime().exec("taskkill /f /im cmd.exe") ;
} catch (Exception e) {
e.printStackTrace();
}
}
}
Surely would help!!
Edit:
To kill a particular process, if u have the PID(from task manager.) you can use taskkill with /pid option.Refer for options here.But anyways you wont have the pid without looking into the task manager.The only solution seems as suggested by this SO answer that you start the process and get hold of the reference.
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