Package javai;import Java.io.bufferedreader;import java.io.InputStreamReader; Public classIotest { Public Static voidMain (string[] args) {Try{Process Pro= Runtime.getruntime (). EXEC ("Ping www.baidu.com"); String Line; BufferedReader buf=NewBufferedReader (NewInputStreamReader (Pro.getinputstream ())); while(line = Buf.readline ())! =NULL) System. out. println (line); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Ping www.a.shifen.com [220.181.111.188] has 32 bytes of data:
Reply from 220.181.111.188: Byte =32 time =28ms ttl=54
Reply from 220.181.111.188: Byte =32 time =28ms ttl=54
Reply from 220.181.111.188: Byte =32 time =28ms ttl=54
Reply from 220.181.111.188: Byte =32 time =28ms ttl=54
Ping Statistics for 220.181.111.188:
Packet: Sent = 4, received = 4, lost = 0 (0% missing),
Estimated time to round trip (in milliseconds):
Shortest = 28ms, longest = 28ms, average = 28ms
Java execution command-line command