0

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());
            }
        }

    }
Gadium
  • 11
  • 4
  • Possible duplicate of [With Java, run multiple commands in the same cmd.exe window](https://stackoverflow.com/questions/24405681/with-java-run-multiple-commands-in-the-same-cmd-exe-window) – Akceptor Nov 12 '18 at 12:44
  • @GauravRai1512 Thank you for the interest and help but the solution you propose does not fit into what I was looking for the application I have to do. For now I will leave it as it was and keep trying. Thank you. – Gadium Nov 12 '18 at 16:42

0 Answers0