So I got around to writing some startup batch scripts that try to mount some network drives. The net use
command is easy enough to use, but I ran into a separate problem. If the machine starts up too fast, then the network isn’t up yet, so net use fails.
So I started looking for a way to delay execution until I knew the network was up. Well pinging in a loop seemed like a good idea.
I’ll start with the end result first:
:loop echo pinging host ping -n 1 host | find "TTL=" > NUL if errorlevel 1 goto loop
So I’ll forgive the fact that the batch command language doesn’t really have a while construct. But apparently, not all versions of ping.exe return a exit code of 0 when a ping succeeds. So the recommended way to check for a successful ping is to look for TTL=
in the output, which you can do with find
. Which leads to the abomination above.