String ip = "www.google.ro";
String pingResult = "";
String pingCmd = "ping " + ip + " -c 4";
String s;
try {
Process p = Runtime.getRuntime().exec(pingCmd);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Rezultat ping:\n");
for (int i = 0; i < 4; i++) {
while ((s = stdInput.readLine()) != null) {
System.out.println(s + "\n");
}
}
// read any errors from the attempted command
System.out.println("\nEventualele erori le gasiti mai jos (Any errors are below:\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s + "\n");
}
}
catch (IOException e) {
System.out.println(e);
}
Hello,
I have a little problem with this code, This is what I have, and it's working, however, I need to output the result in a textarea.
The problem is, that it's taking too long to see any result, in the above example, println, is showing the moment ping or any command is displaying something.
When trying to output the result in the textarea, I use:
textarea.append(s + "\n")
Also, this again is working, but it's displaying all the result in one go. What I want is to append each time a ping is showing something, like the sout command.
Anyone have any suggesting on to what I can use here ?
Regards,
Bogdan