« Poor man's high resolution monitor | Main | Drupal's "edit own" permission and Input Formats »

Awesome: Windows batch file ugliness

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.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on December 4, 2007 5:01 PM.

The previous post in this blog was Poor man's high resolution monitor.

The next post in this blog is Drupal's "edit own" permission and Input Formats.

Many more can be found on the main index page or by looking through the archives.