Windows 2003 batch file Sleep/Wait function [duplicate]
Solution 1:
The correct way to sleep in a batch file is to use the timeout
command, introduced in Windows 2000 Server and Windows XP.
To wait 30 seconds:
timeout /t 30
The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak
, which effectively ignores anything the user may press, except an explicit CTRL-C
:
timeout /t 30 /nobreak
Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to NUL
:
timeout /t 30 /nobreak > NUL
Solution 2:
There's a W2K3 resource kit utility called sleep.exe that you can use by calling it in the batch file and telling it how long to "sleep" before moving on to the next command.
Example:
net use X: \server\share /Delete
sleep 300
net use X: \server\share