【发布时间】:2019-01-22 21:33:26
【问题描述】:
我想捕获IPerf3程序的结果并将它们发送到JAVA swing的GUI,并用图表面板表示。
但我遇到了一个严重的问题。
有一个我用过的sn-p代码。
process = Runtime.getRuntime().exec(command);
// read in the output from Iperf
input = new BufferedReader(new InputStreamReader(process.getInputStream()));
errors = new BufferedReader(new InputStreamReader(process.getErrorStream()));
Thread t = new Thread(){
public synchronized void run(){
String input_line = null;
try{
while (input != null && (input_line = input.readLine()) != null && !input_line.equals(""))
{
// System.out.println("getting msg now ...");
parseLine(input_line);
frame.logMessage(input_line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
然后命令示例是“iperf3 -f M -i 1 -c iperf.he.net -p 5201 -P 1 -t 10”。
如您所知,此 iperf3 服务通过以下方式将数据发送到客户端(或服务器) 时间间隔(这里,一秒),所以当我每秒得到一个结果时, 我想一收到就发送到 GUI(在这里, parseLine() 确实做到了) 结果。
但是,当 Thread.run() 的 while 语句中的 parseLine() 得到执行时,当收到所有 10 个结果时,即 iperf3 服务运行完成时。
我怀疑使用有问题
缓冲读取器
用于输入线。
现在,我遇到了这个问题,我希望在 java 和 iperf 方面有丰富经验的开发人员能够真正帮助我。
谢谢,提前。
【问题讨论】:
-
您可以使用ProcessBuilder首先设置输入捕获,然后开始该过程。
标签: java command-line iperf