问题
I'm trying to create a batch file that will ping a certain server and will only display the respond time. I don't mind if value is stored in a variable or not.
If you do a normal ping you get:
Reply from <hostname/server>: bytes=#byte_value time=#time_value TTL=#TTL_value
And I only want:
#time_value
I don't know if i need to use particular tokens
or use findstr
for the time value. I have failed every attempts so far.
Thanks in advance
回答1:
From command line:
==>ping -4 -n 1 google.com|findstr /i "TTL="
Reply from 173.194.112.105: bytes=32 time=17ms TTL=56
==>for /F "tokens=7 delims== " %G in ('ping -4 -n 1 google.com^|findstr /i "TTL="') do @echo %G
17ms
==>
Used in a batch:
for /F "tokens=7 delims== " %%G in ('
ping -4 -n 1 google.com^|findstr /i "TTL="') do @echo %%G
Read entire for /?
or FOR /F Loop command: against the results of another command.
来源:https://stackoverflow.com/questions/30855909/getting-respond-time-from-ping-command