简体   繁体   中英

Stop android adb ping programmatically and print statistics

I am trying to send a ping for x amount of seconds instead of a certain amount of pings and gather the results. I notice that if I shell in and run "ping www.google.com" and stop it with CTRL + C it does not print the statistics, but if I run "ping -c5 www.google.com" the statistics will print. Is there a way to send the ping command, have it time out after a specified time, and then print the ping statistics?

Note: I am sending this programmatically with Java.

C:\Users\Field_Test>adb shell
shell@android:/ $ ping www.google.com
ping www.google.com
PING www.google.com (173.194.46.116) 56(84) bytes of data.
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=1 ttl=54 time
=55.7 ms
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=2 ttl=54 time
=70.9 ms
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=3 ttl=54 time
=60.8 ms
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=4 ttl=54 time
=71.1 ms
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=5 ttl=54 time
=69.8 ms
64 bytes from ord08s13-in-f20.1e100.net (173.194.46.116): icmp_seq=6 ttl=54 time
=72.0 ms
^C

nm, found it. "-w#" will run for a specified time and print the statistics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM