【发布时间】:2016-04-17 23:05:24
【问题描述】:
我已经尝试了这部分的其他链接,但仍然无法获得我需要的东西。因此,我想在这里寻求小组的帮助。
下面是我的代码:
try {
String file = new File("iperf3.exe").getCanonicalPath();
String cmd1[] = {file,"-c","ping.online.net","-P","10","-w","710000"};
Process p1 = Runtime.getRuntime().exec(cmd1);
BufferedReader input1 = new BufferedReader(new InputStreamReader(p1.getInputStream()));
String line1;
while ((line1 = input1.readLine()) != null) {
txtConsole1.setText(line1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
到 textArea 的输出消息只是执行命令的最后一条消息。我可以知道如何将所有输出消息流式传输到 textArea 中吗?
谢谢。
【问题讨论】:
-
你要么阻止了 EDT,要么违反了 Swing 的单一规则,这两种情况都不漂亮。查看Concurrency in Swing 和Worker Threads and SwingWorker 了解更多详情
标签: java swing process jtextarea