I have opened a commnad prompt using java program and another command prompt manually. Now my requirement is that i need to close the command prompt that i have opened by ja
you can try to program "exit" into the command prompt after you are done with your tasks in command prompt
if you're using Runtime.getRuntime().exec(), it returns a Process object. You should hold on to that and call Process.destroy() when you're done.
It's simple -
Step 1
- Create a batch file (say closeCMD.bat)
Step 2
- write exit in closeCMD.bat
Step 3
- call above batch file in your java code as below -
Runtime.getRuntime().exec("cmd /c start closeCMD.bat");
That's it !! Cheers!!