PDF download Download Article PDF download Download Article

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. 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] . [2]
    • To pause for 30 seconds and prevent the user from interrupting the pause with a keystroke, you'd enter timeout /t 30 /nobreak . [3]
      • 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
  1. 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. [4]
    • 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. [5]
    • At the pause, you can stop the batch program completely by pressing Ctrl + C and then Y .
  1. 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. [6]
    • 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
  1. 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. [7]
    • 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).
  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

Search
Add New Question
  • Question
    How do I not get a message when I use timeout?
    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
    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
    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.
See more answers
Ask a Question
      Advertisement

      Tips

      • You can run a batch file on any Windows computer by double-clicking it, or launch it from the command prompt .
      • The "PAUSE" command is best used in situations where you're relying on a user to trigger the next section of the batch file, while the "TIMEOUT" command is suited to situations in which you want to allow the file to run automatically.
      • The formerly used "SLEEP" command does not work on Windows Vista or later, including Windows 10 and 11.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 1,583,638 times.

      Reader Success Stories

      • Nangah Shikari

        Jun 6, 2016

        "This is great. The ping one, especially. I was working on crashing computers and I worked out that it takes 128 ..." more
      Share your story

      Is this article up to date?

      Advertisement