Home > Computer network, Microsoft, Quickie, Windows > Quickie: Batch file didn’t wait for ping command

Quickie: Batch file didn’t wait for ping command

Today I was needed to make batch script to ping some IP addresses for problem described in this article. My first script was as following:

@Echo Off


ping -n 1 -w 30000 >NUL

ping -n 1 | find /i “bytes=” || goto FailedPing

goto Loop1


echo FAILED PRIMARY NET TO VIA %time% >>ping_test.log

route delete mask

route add mask

goto Loop1

When I ran this script in cmd.exe or I scheduled it, it ate one CPU core. I didn’t know why it’s happening, because when I ran this commands in cmd.exe separatelly it workied fine. After couple minutes of debugging I found out that script is not waiting for “ping” commands to finish. It was weird. My colleague told me to use “sleep.exe” to make it wait for a little bit. But that was not a solution. I wanted to force it to wait for ping commands. I tried weird thing. Instead of “ping” I used whole path for ping.exe “%SystemRoot%\\System32\\ping.exe” and for command “route” I used “%SystemRoot%\\System32\\route.exe”. Now everything looks and works perfect.

I have no idea why this is happening, but it works and I need to remember it 🙂

  1. No comments yet.
  1. No trackbacks yet.