My code must run a .jar that generates a series of strings. I enter how many times I want to run the .jar and how many strings are generated each time the application runs. I can do it but each time a new CMD window opens. How can I make it show up in a single window?
I know this is so because I'm creating cmd.exe processes in the loop but I've tried other codes where I don't create cmd.exe processes and I can't get it to work.
Thanks.
public static void main(String args[]) {
Process newpro;
int reps = 0, stri = 0;
String command = "cmd /C start cmd.exe /K java -jar D:\\Documents\\NetBeansProjects\\Array\\dist\\Array.jar";
System.out.println("How many times do you want to launch the app?");
reps = readInt(0, 10);
System.out.println("How many strings do you want to create in each repetition?");
stri = readInt();
for (int i = 0; i < reps; i++) {
try {
newpro = Runtime.getRuntime().exec(command + " " + stri);
} catch (SecurityException ex) {
System.out.println("Error.");
} catch (Exception ex) {
System.out.println("Error: " + ex.toString());
}
}
}