Tutorial :How to close command windows with Java


Each time I use Runtime.exec("cmd /c start....") I am opening a cmd window. I would like to create a more seamless application by closing each previous cmd window. How can I do this?

If anyone knows of a better way to run a series of commands in the same cmd window rather than opening new ones each time I execute a command, please let me know.


You cannot control the opened windows from Java. But I suggest two solutions for you:


Runtime.exec("cmd /c start /MIN ...")  

The /MIN parameter will prevent windows from appearing.

Second: put all the applications you must call inside the same batch file and call it once. :-)


Don't use start, that opens another window


Runtime.exec("cmd /c start....")  


Runtime.exec("cmd /c ....")  


Why do you need cmd windows?

I'd run the command directly in Java and capture the output and display it in a local window (if it's needed at all).

Just make sure you consume all the output from the program or it might stall. Also remember to close the stdout, stderr, and stdin streams or some file handles might leak (well, that's true on some JDKs on some Unix OSes... Windows, who knows).

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »