Question

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.

Was it helpful?

Solution

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

First:

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. :-)

OTHER TIPS

Don't use start, that opens another window

Replace:

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

with:

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top