I got a sample ping program with a little modification...
String ip = "192.168.1.1 -t";
String pingResult = "";
String pingCmd = "ping " + ip;
try{
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
Pattern pattern = Pattern.compile("time=(\\d+)ms");
Matcher m = null;
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
m = pattern.matcher(inputLine);
if (m.find()) {
System.out.println(m.group(1));
}
}
in.close();
}
catch (IOException e) {
System.out.println(e);
}
I going to implement a GUI which include a start and exit button, the start button works but the exit buttons won't. When I click the exit button, the program do not show the rtt time output. But the program do not actually exit-ed/ stopped. How am I totally to shut it down, am I going to add something likeRuntime.getRuntime().addShutdownHook
.
Need some hints and guidelines, thanks in advanced...