在 Java 的可见命令提示符窗口中对 Nmap 命令进行排队

发布于 2024-09-17 06:37:13 字数 836 浏览 9 评论 0原文

我正在尝试依次运行多个 Nmap 命令。

理想情况下,每个 Nmap 命令都将在其自己的命令提示符窗口中创建。 Nmap 命令将执行并完成。然后会出现另一个命令提示符,并显示下一个 Nmap 命令、执行等等。

不幸的是,按照程序当前的运行方式,多个命令提示符窗口会同时弹出并同时执行。我希望这些命令一次只执行一个。我原以为 waitFor() 方法可以解决问题,但事实并非如此。我错过了什么吗?

我已经从我的实际程序中大大简化了这一点以解决核心问题。任何帮助将不胜感激。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2024-09-24 06:37:14

这是因为你正在做一个“开始”。该进程将启动另一个进程来处理 nmap 命令,并在不等待该子进程终止的情况下终止。

删除“开始”应该使窗口一个接一个地显示。

This is because you are doing a "start". The process will start another one to handle the nmap command, and terminates without waiting for that child process to terminate.

Removing the "start" should make the windows show one after the other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文