I am trying to run multiple Nmap commands one after another.
Ideally, each Nmap command will be created in its own command prompt window. The Nmap command will execute and finish. Then another command prompt will appear with the next Nmap command, execute, and so on and so forth.
Unfortunately, the the way the program currently runs, multiple command prompt windows pop up at the same time and execute simultaneously. I want the commands to execute only one at a time. I had thought that the waitFor() method would solve the problem, yet it hasn't. Am I missing something?
I have simplified this greatly from my actual program to solve the core issue. Any help would be appreciated.
try {
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "nmap", targets, "-p 1- 65535", "-oN +output");
Process p = pb.start();
p.waitFor();
System.out.println("p done");
Process z = pb.start();
z.waitFor();
System.out.println("z done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}