0

I have tried the others link on this portion, but still unable to get what I need. Thus I would like to seek help from the group here.

Below is my code:

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

The output message to the textArea is only the last message from executing the command. May I know how can I stream all the output messages into the textArea?

Thank you.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Adrian Tan
  • 33
  • 8
  • You're either block the EDT or violating the single rules of Swing, in either case not pretty. Have a look at [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) and [Worker Threads and SwingWorker](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for more details – MadProgrammer Jan 13 '16 at 05:16

1 Answers1

0

You are overriding previous content of txtConsole1 by calling txtConsole1.setText(line1);. Get all your output in variable and at last set content in txtConsole1

String line1;
String content;
while ((line1 = input1.readLine()) != null) {
    content += line1;
}
txtConsole1.setText(content);
Vicky Thakor
  • 3,847
  • 7
  • 42
  • 67