what I would like to do is run a batch
file multiple times from a java application. Therefore I set up a for-loop
that runs this code n
times:
for (int i = 0; i < n; i++) {
Runtime.getRuntime().exec("cmd /c start somefile.bat");
}
The problem is that now each time the command is run a new cmd window pops up. However, what I want is just one window that pops up at the beginning and that is used to display all data from the following command calls.
How can I do that?
With && you can execute more than one commands, one after another:
I would use Java's ProcessBuilder or another class which simulates/uses a shell. The following snippet demonstrates the idea (for Linux with bash).
Please note that it is only a snippet, which needs to be adapted for Windows, but in general it should work with
cmd.exe
.