I was working on another batch file today and needed a way for the script to wait for a given number of seconds before continuing to execute. On a whim, I tried the wait command by adding “wait 30“, thinking the script would wait at that spot for 30 seconds before continuing.
The script did wait for 30 seconds, but instead of continuing to execute, it simply exited at that point, leaving the rest of the commands unfinished.
After spending a few minutes trying to get more information about the wait command, I gave up and decided to see what the web had to offer.
There were lots of suggestions, but most of them were of the “twine and bailing wire” approach. Being one to keep things simple, I checked forum after forum until I came upon the timeout command.
The timeout command was introduced in Windows Vista and thankfully is also included in Windows 7. Its one and only purpose is to wait a specified number of seconds – exactly what I was looking for!
Adding the following line will cause your batch file to pause for 30 seconds, then continue on its merry way:
timeout /T 30
As an added bonus, timeout adds a message in the cmd window telling you what its doing and even counts down, telling you how many seconds are left.
timeout /T 30 Waiting for 27 seconds, press a key to continue ...
If you add the /NOBREAK option, random key presses are ignored:
timeout /T 30 /NOBREAK Waiting for 27 seconds, press CTRL+C to quit ...
If you don’t want any message printed out, just redirect the output to nul:
timeout /T 30 /NOBREAK > nul
Kudos to: commandwindows.com for this tip.
Pretty nice post. I just stumbled upon your weblog and wished to say that I have truly enjoyed browsing your weblog posts. After all I’ll be subscribing on your rss feed and I hope you write once more soon!
LikeLike
timeout don’t work on batch file
example:
timeout /T 30 /NOBREAK > nul
or
timeout /T 30 /NOBREAK
😦
LikeLike
Timeout was first introduced on Windows 7, it won’t work with XP or Vista. With which OS are you trying to use it?
LikeLike