If you need some extra time for a command in your batch file to execute, there are several easy ways to delay a batch file. While the well-known sleep command from older versions of Windows is not available in Windows 10 or 11, you can use the timeout, pause, ping, and choice commands to wait a specific number of seconds or simply pause until the user presses a key. This wikiHow article will teach you 5 simple ways to delay the next command in your batch file on any version of Windows.

Things You Should Know

  • The timeout command lets you pause for specific number of seconds, until a user presses a key, or indefinitely.
  • Use the pause command to delay the batch file until a user presses any key, or the choice command to give the user options to choose from.
  • You can hide on-screen messages that indicate delay to the user by adding >nul to the end of the timeout, ping, and choice commands.
1

Timeout

  1. Use the timeout command to specify the delay time in seconds. By inserting the timeout command into your batch file, you can prompt the batch file to wait a specified number of seconds (or for a key press) before proceeding.[1] This command is available on all modern versions of windows, including Windows 10.
    • timeout /t <timeoutinseconds> [/nobreak]
    • To pause for 30 seconds and prevent the user from interrupting the pause with a keystroke, you'd enter timeout /t 30 /nobreak.
      • The user will see Waiting for 30 seconds, press CTRL+C to quit ...
    • To delay 100 seconds and allow the user to interrupt the delay, you'd use timeout /t 100.
      • The user will see Waiting for 100 seconds, press a key to continue ...
    • To delay indefinitely until a user enters a keystroke, use timeout /t -1.
      • The user will see Press any key to continue …
    • If you don't want to display a message to the user during the delay, add >nul to the end of your timeout command.
  2. Advertisement
2

Pause

  1. Use the pause command to suspend the batch file until a user presses a key. This simple command doesn't require any flags and you can place it anywhere in your script to prevent further action. When the pause command runs in the batch file, the user will see Press any key to continue . . . on a new line. When the user presses a key, the script continues.
    • You might use pause right before a section of the batch file that you might not want to process, or before providing instructions to the user to insert a disk before continuing.[2]
    • At the pause, you can stop the batch program completely by pressing Ctrl + C and then Y.
3

Ping

  1. Use ping to delay the next command in the script until a ping is complete. You can add a ping anywhere in your batch file, enter any hostname or IP address (including a nonexistent address), and specify the time in milliseconds to delay the next command. You'll also be able to hide the output of the ping so the user won't see what's happening in the background.
    • ping /n 1 /w <timeout in milliseconds> localhost >nul
      • Ping has many more available flags, but for the purpose of delaying a batch file, you'll only need to use a few. In this case, we'll ping ourselves by using localhost as our destination.
      • To pause quietly for 10 seconds, you'd use ping /n 1 /w 10000 localhost >nul
  2. Advertisement
4

Choice

  1. Use the choice command to delay until a user selects an option from a list. You can customize the list of choices, use the default options of Y or N, or choose not to display any choices at all and simply delay your script for a specific period of time.
    • choice [/c [<choice1><choice2><…>]] [/n] [/cs] [/t <seconds> /d <choice>] [/m <text>]
      • /c <choice1><choice2><…>: Specifies the choices you'd like to create, which can include a-z, A-Z, 0-9, and ASCII characters 128-254.
      • /t <seconds>: Use this flag to specify how many seconds to wait before the default choice is selected. You can set this value to any number between 0 (which instantly selects the default choice) and 9999.
      • /d <choice>: Specifies the default choice from the list of choices created with /c.
      • /n (optional): hides the list of choices, but still allows the user to select one.
      • /m <text> (optional): displays a message before the choice list. If you don't include this flag but don't hide the choice list, the choices will still be displayed.
      • /cs (optional): This specifies that choices are case-sensitive, which is important if you want to assign different functions to capital and lowercase letters.
    • To create a delay with CHOICE without displaying a message or forcing the user to choose something, use rem | choice /c:AB /T:A,30 >nul. This command simply delays the batch file for 30 seconds (similar to using Timeout with no message), provides no choices to the user, and continues after the delay. You can replace 30 with any value up to 9999 (in seconds).[3]
5

Sleep

  1. If you're using Windows XP or earlier, you can use sleep to specify a wait time in seconds. This command will not work in any newer versions of Windows starting with Windows Vista, but is the easiest way to add wait time to batch files running on older systems.
    • sleep <seconds>
    • The sleep command only requires the number of seconds you want to delay the batch file. For example, to wait 30 seconds before continuing, you'd use sleep 30.
  2. Advertisement

Community Q&A

  • Question
    How do I not get a message when I use timeout?
    Community Answer
    Community Answer
    Add the >nul qualifier, like this: timeout /t 120 >nul. This causes a 2 minute delay with no output to the screen.
  • Question
    What if the sleep command doesn't work?
    Community Answer
    Community Answer
    If the sleep command doesn't work, use timeout instead.
  • Question
    What if I want to wait less than one second? I can't just use a dot or a comma.
    Community Answer
    Community Answer
    You can use the ping command. This command, if used with a non-existent IP address, will try to talk to a non-existent computer and give up after a specified number of milliseconds. Just multiply the number of seconds by 1000, and you're good to go.
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 1,309,717 times.
How helpful is this?
Co-authors: 27
Updated: October 25, 2022
Views: 1,309,717
Categories: Programming
Article SummaryX

1. To pause until a key is pressed, use "PAUSE."
2. To wait a specific amount of time, use "TIMEOUT."
3. To wait for a ping response, use "PING" followed by the IP.

Did this summary help you?
Advertisement