TIMEOUT.exe

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

Syntax
      TIMEOUT [/T] delay [/nobreak] 

Key
   delay  Delay in seconds (between -1 and 100000) to wait before continuing. 
          The value -1 causes the computer to wait indefinitely for a keystroke 
          (like the PAUSE command)

   /nobreak
          Ignore user key strokes, timeout can still be interrupted with Ctrl-C.

Timeout will pause command execution for a number of seconds, after which it continues without requiring a user keystroke. If the user presses a key at any point, execution will resume immediately.

A timeout of 1 second will wait until the "next second" so in practice may be as short as 1/10th of a second.

Unlike Sleep or Ping, Timeout is based on the system time, so if at 23:00 you issue Timeout 600 the delay will be until 23:10, if the system clock is then changed, either manually or due to a Daylight Savings switch, the delay will still end at that same clock time. This can produce a longer or shorter delay than expected. If the system clock is moved forward past the expected time, it will end immediately.

Alternative: delay using Ping

A more accurate 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

The PING command can only be interrupted with Ctrl-C.
Source: Clay Calvert’s newsgroup posting.

To call this 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 a specified number of seconds. Source: StackOverflow

Examples

Start applications in turn:

@Echo off
Echo Start Microsoft Word, wait for 10 seconds and then start Excel.
START "" "C:Program Files\Microsoft Office\Office16\WINWORD.EXE"
TIMEOUT /T 10
START "" "C:Program Files\Microsoft Office\Office16\EXCEL.EXE"

Set a delay for 40 seconds:

PING -n 41 127.0.0.1>nul
Echo Now we are ready

Wait for up to 600 seconds for a file to appear on a remote server:

Set _seconds=0
:waitloop
  :: Wait for 10 seconds
  Set /a "_seconds=_seconds+10">nul
  PING -n 11 127.0.0.1>nul
  :: If 600 seconds have elapsed exit the loop
  if %_seconds%==600 goto nextstep
  if not exist \\Server64\updates\monday.csv goto waitloop
:nextstep 
copy \\Server64\updates\monday.csv D:\imports\

“It is awful work this love and prevents all a mans projects of good or glory” ~ Lord Byron

Related commands

CHOICE /T Timeout - Accept keyboard input to a batch file.
PAUSE - Suspend processing of a batch file and display a message.
SLEEP - Delay execution for a few seconds/minutes (for use within a batch file).
WAITFOR - Wait for or send a signal.
Equivalent PowerShell: Start-Sleep - Suspend shell, script, or runspace activity (sleep).


 
Copyright © 1999-2025 windevcluster.com
Some rights reserved