TIMEOUT - CMD


Overview

The TIMEOUT command in Windows CMD is used to delay the processing of a batch file for a specified number of seconds. This utility is valuable in scripting to pause the execution temporarily, allowing for processes or services to start-up or to provide a buffer time before executing subsequent commands. It is most effectively used in automated scripts where sequential operations require a specific timing between them, aiding in synchronizing processes or creating pauses for user interaction.

Syntax

TIMEOUT /T timeout [/NOBREAK]
  • /T timeout: Specifies the delay time in seconds.
  • /NOBREAK: Optional. Prevents a key press from interrupting the wait.

The TIMEOUT command must have the /T parameter indicating the number of seconds to wait. The absence of the /NOBREAK option allows the command to be interrupted by pressing any key.

Options/Flags

  • /T timeout: The delay time, in seconds, that the command should wait before returning control to the CMD window or batch file. It is required to specify this option.
  • /NOBREAK: If included, the TIMEOUT will ignore any key press and will not interrupt the delay, except for Ctrl+C.

Examples

  1. Basic Usage: To pause for 30 seconds in a batch script.
    TIMEOUT /T 30
    
  2. Prevent Interruption: Make the timeout not interruptible by user key presses, delaying for 10 seconds:
    TIMEOUT /T 10 /NOBREAK
    
  3. Combined in a script: Pausing between two commands in a script.
    @echo off
    echo Starting the process.
    TIMEOUT /T 5
    echo Process started.
    

Common Issues

  • Invalid Input Error: Errors occur if the timeout duration is set with letters or special characters. Make sure to specify the delay as a numerical value.
  • Unexpected Termination: Without the /NOBREAK option, users pressing any key can shorten the wait time, which might be undesirable in some scenarios.

Integration

TIMEOUT can be integrated with other CMD commands or scripts for automated tasks. For example, you may want to wait for a specific service to launch or stabilize before executing the next command.

Script Example: Using TIMEOUT between network commands:

@echo off
ipconfig /release
TIMEOUT /T 5 /NOBREAK
ipconfig /renew
echo IP configuration has been refreshed.
  • SLEEP: Offers similar functionality with different options.
  • PAUSE: Used in batch files to pause the script until a key is pressed.

For further details on the TIMEOUT command and its scenarios, you can visit the official Microsoft documentation.