String cmd = "cmd.exe /c ping 8.8.8.8"; //Command to execute
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(cmd);
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "Shift-JIS");
BufferedReader reader = new BufferedReader(isr);
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
output
8.8.8.Pinging to 8 32 bytes of data:
8.8.8.Response from 8:Number of bytes=32 hours=15ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=13ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=12ms TTL=57
8.8.8.Response from 8:Number of bytes=32 hours=13ms TTL=57
8.8.8.8 ping stats:
Number of packets:Send=4, receive=4, loss= 0 (0%Loss)、
Approximate round trip time(millisecond):
minimum=12ms, maximum=15ms, average= 13ms
Recommended Posts