Windows – How to sleep in a batch file

batchbatch-filewindows

How to pause execution for a while in a Windows batch file between a command and the next one?

Best Answer

The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000.

To wait somewhere between 29 and 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