5

Possible Duplicate:
How to sleep in a batch file?

I have a batch file that runs as a secheduled task in windows server 2003.

This batch file purely calls around 20 other batchfiles one after the other.

When this runs it causes quite a spike on the server and a reduction in performance.

I'd like the ability to add a WAIT or SLEEP type command between each of my batch file calls in order to spread the load out a bit.

Can anyone shed any light on the simplest way of doing this?

Robin Day
  • 506
  • 1
  • 8
  • 19

4 Answers4

14

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
Synoli
  • 103
  • 3
Massimo
  • 68,714
  • 56
  • 196
  • 319
1

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

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
-3

The best way is to use 'ping', but you can find more ways here: http://drbatcher.blogspot.com/2009/10/pauses-and-delays-in-batch-scripts.html

Roger
  • 9
-5

The code you are looking for, looks like this:

ping -n 11 127.0.0.1 > NUL

The value after "-n" indicates the seconds to wait.
If you want to wait 10secs just add one more ping,
like shown in the example.

Best regards.

P.S.: If you use the powershell, there may be other ways to do this.

Phil Swiss
  • 1,437
  • 9
  • 4