0

我正在尝试通过我的 Java 应用程序执行网络测试应用程序。下面是代码:

try {
    String file = new File("iperf3.exe").getCanonicalPath();
    String cmd[] = {file,"-c ping.online.net -P 20 -w 710000 -t"};
    Process p = Runtime.getRuntime().exec(cmd);

    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String line;
    while ((line = input.readLine()) != null) {
        lblConsole.setText(line);
        //System.out.println(line);
    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

我收到一条错误消息,提示应用程序无法连接到服务器。但是,当我在命令提示符下执行命令时,没有错误。

我可以知道我在这里错过了什么吗?

4

1 回答 1

0

设法解决了这个问题。这主要是关于我如何在cmd中执行代码。刚刚更新如下:

String file = new File("iperf3.exe").getCanonicalPath(); String cmd1[] = {file,"-c","ping.online.net","-P","10","-w","710000"};
于 2016-01-13T05:11:57.723 回答