I'm trying to persistantly ping a destination, say google.co.uk, to determine how reliable the internet is at one of my locations. I am running this ping test for about a month in order to get a good grasp of whether the internet between 6am and 10am, and 4pm and 7pm, is going to suit transferring live audio over it at the busiest times for internet traffic in the day.

I'm getting an annoying logfile...:

With my code in the bat file:

FOR /f "tokens=1-8 delims=:./ " %%G IN ("%date%_%time%") DO (SET datetime=%%G%%H%%I_%%J_%%K)

ping google.co.uk -t |find /v ""|cmd /q /v:on /c "for /l %%a in (0) do (set "data="&set /p "data="&if defined data echo(!time! !data!)" >> D:\filename_%time:~0,2%%time:~3,2%-%date:~-10,2%%date:~3,2%%date:~-4,4%.txt'

It's producing:

18:23:07.24 Reply from bytes=32 time 18:23:07.24 =12ms TTL=54 18:23:08.24 Reply from bytes=32 time 18:23:08.24 =12ms TTL=54 18:23:09.24 Reply from bytes=32 time 18:23:09.24 =12ms TTL=54

Where the one result is split over two lines... What am I doing wrong? And is there a solution?

Thanks in advance.


I use the following batch file for a similar purpose:

@echo off

set HostToPing="google.com"

set datetime=%date% %time%
for /f "tokens=9" %%g in ('ping %HostToPing% ^| find "Average ="') do echo %datetime% %%g >>ping_times.txt
timeout /t 120
goto loop
| improve this answer | |
  • Thanks for getting back to me. I've tried this but it's already broken my PC once. It just hung the cmd window, running up multiple cmd processes and another process I now can't remember the name of... :-( It also didn't output to anything after I adjusted the path to put the log. I haven't yet read your site to progress with it, I keep getting called away to do other things. I'll let you know what further progress I make. Thanks again. – Jon Talbot Mar 10 '17 at 13:24

Read here. This behaviour is caused by a syncronization problem. The set /p in the right side of the pipe that reads data from the ping output starts a read operation while the ping is writing but has still not send a carriage return.

But the code in the indicated answer (keep a continuous ping to a single named machine) only has sense if you want to keep the ping running against a single precise machine avoiding any additional name resolution, round robin dns, ... just to ping all the time against a single machine.

But if, as stated, you want to test the internet connection, not the target machine, a simple batch file (ex. moonpoint's answer) is a better option.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.