- 1 year ago
How can i show time output only from ping command?
To show only the time output from the ping
command in Windows, you can use the following command:
shellping -n 1 google.com | findstr "time="
This command sends a single ICMP echo request to google.com
using the -n 1
option, and then pipes the output to findstr
to filter and display only the lines containing "time=". The "time=" lines will show the round-trip time for the ping request.
Note that the specific output format may vary depending on your system and the version of the ping
command. Adjust the findstr
pattern accordingly if needed.
If you want to capture the time value and store it in a variable for further processing, you can use the for
loop as follows:
shellfor /f "tokens=7 delims== " %i in ('ping -n 1 google.com ^| findstr "time="') do set "time=%i"
echo %time%
In this example, the for /f
loop captures the time value from the ping
command output using the specified findstr
pattern, and assigns it to the %i
variable. You can then access the time value using %time%
and perform any additional processing as needed.
Note that if you're using this command in a batch script, you need to use %%i
and %%time%%
instead of %i
and %time%
.