Arnout's Eclectica

But I digress…

Synchronizing two batch files using WAITFOR.exe

28 August 2008 22:58 — Development,Reminder,Windows

I was writing some unit tests today where I wanted to start some process asynchronously, but have it automatically exit after a specified number of seconds. Preferably something that's available on a standard W2K3 box, so that I wouldn't be creating any additional prerequisites for other developer boxes or the build machine.

Usually I just use ping -t -n count host for this, but I was also thinking that it would be nice to be able to terminate the process before the timeout. Not sure exactly how I came across it, but somehow I found waitfor.exe lying around in my system32 directory.

WAITFOR uses a mailslot to wait on or send a signal to. The waiting and sending can happen on the same machine, or the signal can be sent across the network.

In one command prompt, you perform the wait:

C:\\> WAITFOR /T 42 SignalName

In another, you send the signal:

C:\\> WAITFOR /SI SignalName

Way nicer than the old-fashioned approach of having process A poll a directory until process B has created a particular file. And, no less important, if the signal is not received within the specified timeout, you get:

C:\\> WAITFOR /T 1 Godot
ERROR: Timed out waiting for 'Godot'.

C:\\>_

:-)

2 Comments »

  1. Is this a ‘normal’ windows tool, because I cannot find this on my pc.

    Comment by Daniel — 30 October 2008 @ 16:18

  2. It seems to come with Windows Server 2003 and Windows Server 2008 out of the box, but I just tried it on a vanilla Windows XP installation, and there it wasn’t available.

    I can’t check Vista at the moment, but I did see it included in a list of Vista command line tools.

    I guess you’re using Windows XP? In that case, you seem to be out of luck. Sorry about that…

    Comment by Arnout — 30 October 2008 @ 16:42

RSS feed for comments on this post. TrackBack URI

Leave a comment

Copyright © 2006-2009 Arnout Grootveld — Powered by WordPress — Hosted at pair Networks