SLEEP.exe (2003 Resource Kit)

Delay execution for a few seconds/minutes, for use within a batch file.

Syntax
      SLEEP time

Key
   time  The number of seconds to pause

Examples

Pause for 10 seconds before running the next command in a batch file:

SLEEP 10

Alternative: delay using Ping

A delay can also be produced by the PING command with a loopback address (127.0.0.1), in tests this consumes less processor time than Sleep.exe or Timeout.exe. The delay between each ping is 1 second, so for a delay of 5 seconds ping 6 times.

e.g. for a delay of 30 seconds:
PING -n 31 127.0.0.1>nul

Source: Clay Calvert's newsgroup posting.

To make this less ugly, consider using a subroutine, add the following to the end of your batch file:

@goto :eof
:timeout
:: use ping to delay for the number of seconds passed as an argument
@ping -n %1 127.0.0.1 > nul
@ping -n 2 127.0.0.1 > nul
@goto :eof

Then you can use 'call :timeout 30' to delay for the specified number of seconds. Source: StackOverflow

“O sleep, O gentle sleep, nature's soft nurse, how have I frighted thee, that thou no more wilt weigh my eyelids down, and steep my senses in forgetfulness” ~ Shakespeare (Henry IV)

Related commands

TIMEOUT - Delay execution for a few seconds/minutes (for use within a batch file.)
WAITFOR - Wait for or send a signal.
PING - Test a network connection.
WScript.Sleep - Sleep
Equivalent PowerShell: Start-Sleep - Suspend shell, script, or runspace activity (sleep)
Equivalent bash command: sleep - Delay for a specified time.


 
Copyright © 1999-2024 SS64.com
Some rights reserved