Create your own sleep / wait program

It can be useful in batch files to have the ability to perform a wait operation for a certain time period. Ex. if polling for a certain event (like a file being created by another program), or if having to perform an action with a certain period of time in between. There is no sleep or wait operation available in DOS, but you can create your own version.

CHOICE can be used where one specifies that it should pick the default after a certain period of time. Create a batch file WAIT.BAT with the following lines:

@REM The > NUL make sure that the screen output from choice is not shown
@CHOICE /T:N,%1% > NUL

If not having CHOICE available, but have TCPIP PING then one can use this instead:

@REM The > NUL make sure that the screen output from choice is not shown
@PING 1.0.0.0 -n %1 -w 10 > NUL

To use WAIT.BAT, call it like this:

CALL WAIT 10

Updated: 23 September 2007

Tags:
Category:

Leave a Reply

Your email address will not be published. Required fields are marked *