简体   繁体   English

以编程方式停止android adb ping并打印统计信息

[英]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. 我正在尝试发送x秒钟的ping(而不是一定数量的ping)并收集结果。 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. 我注意到,如果我安装并运行“ ping www.google.com”并用CTRL + C停止它,则不会打印统计信息,但是如果我运行“ ping -c5 www.google.com”,则将打印统计信息。 Is there a way to send the ping command, have it time out after a specified time, and then print the ping statistics? 有没有一种方法可以发送ping命令,在指定的时间后使其超时,然后打印ping统计信息?

Note: I am sending this programmatically with Java. 注意:我正在使用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. nm,找到它。 "-w#" will run for a specified time and print the statistics. “ -w#”将运行指定的时间并打印统计信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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