How to wait in a batch script
How to Delay a Batch File
This wikiHow teaches you how to prevent a batch file from running immediately after being opened. There are a few different commands you can use to delay your batch file depending on your needs. Keep in mind that you should have a fairly firm grasp on how to write a batch file before attempting to delay one.
Open Start .Click the Windows logo in the bottom-left corner of the screen.
- If you have an existing batch file you'd like to delay, right-click the file, then clickEditto open the file in Notepad. You can then skip the next two steps.
Open Notepad.Type innotepadto search for Notepad, then clickNotepadat the top of the Start window.
Create your batch file.Often starting with [email protected] offcommand, enter your batch file's text as needed.
Determine how you want to delay your file.There are three main commands you can use to delay a batch file:
- PAUSE— Causes the batch file to pause until a standard key (e.g., the spacebar) is pressed.
- TIMEOUT— Prompts the batch file to wait for a specified number of seconds (or a key press) before proceeding.
- PING— Pauses the batch file until the file receives a return ping from a specified computer address. This usually results in only a small delay if you ping a working address.
Select a place to delay your file.You can delay a batch file at any point in the code (save for after the "Exit" command if you used one). Scroll down until you find the point at which you want to delay the file, then create a space between the code before the delay point and the code after.
Type in your command.Depending on your preferred command, do one of the following:
- PAUSE— Typepauseinto the line. You don't need to add anything else here.
TIMEOUT— Typetimeout timewhere "time" is replaced by the number of seconds to delay. For example, typing intimeout 30will delay your batch file for 30 seconds.
- If you want to prevent people from skipping the delay with a keypress, type intimeout time /nobreak(where "time" is the number of seconds to wait).
- PING— Type inping addresswhere "address" is the IP address for a computer or website you want to PING.
Save your document as a batch file.If you haven't yet saved your document as a batch file, do the following:
- ClickFile, then clickSave As....
- Type in your file's name followed by.bat(e.g., "My Batch File" would become "My Batch File.bat").
- Click the "Save as type" drop-down box, then clickAll Files.
- Select a save location, then clickSave.
QuestionHow do I not get a message when I use timeout?wikiHow ContributorCommunity AnswerAdd the >nul qualifier, like this: timeout /t 120 >nul. This causes a 2 minute delay with no output to the screen.Thanks!
QuestionWhat if the sleep command doesn't work?wikiHow ContributorCommunity AnswerIf the sleep command doesn't work, use timeout instead.Thanks!
QuestionWhat if I want to wait less than one second? I can't just use a dot or a comma.wikiHow ContributorCommunity AnswerYou 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.Thanks!
QuestionWhat can I do if the PING command skips?wikiHow ContributorCommunity AnswerMake sure that you are using an invalid IP address. Also, remove '>nul' from the end and see what it outputs -- this might tell you why it skips.Thanks!
QuestionHow do I check if a folder is created?David LangrCommunity AnswerIn this case, you can use "Parenthesis": @echo off IF EXIST "C:\Folder" ( echo Folder exists! ) ELSE ( Echo Folder does not exist! ) pause > nulThanks!
QuestionHow do I delete the message for ping?wikiHow ContributorCommunity AnswerYou should have: ping [a fake ip] Add >nul Now it should look like this: ping [a fake ip] >nulThanks!
QuestionHow do I get rid of a warning message for a time out?wikiHow ContributorCommunity AnswerTo get rid of the warning message for a timeout, out >nul at the end of the line, and it will hide the warning.Thanks!
What can I do if I need to loop a ping but it keeps repeating itself instantly?
- You can run your batch file on any Windows computer by double-clicking it.
- 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 10.
- Batch files won't run on Mac computers.
Sources and Citations
In other languages:
Español: , Italiano: , Português: , Русский: , Deutsch: , Français: , Bahasa Indonesia: , Nederlands: , ไทย: , العربية: , 中文:
of How to Delay a Batch File was reviewed on July 11, 2019.
Jun 6, 2019
Mar 14, 2019
Mar 1, 2019
Jul 20, 2019
Sep 7, 2019
Nov 12, 2019
Aug 11, 2019
Nov 17, 2019
Aug 4, 2019
Jul 11, 2019
Jul 27, 2019
Jul 23, 2019
Video: Batch Scripting - 9 - Custom Pause and Animation
The 13 Best Bulges of 2019
N this Tuesday Feb. 27, 2012 photo, Kathy Deady holds up a tube of Naloxone Hydrochloride, also known as Narcan, in her Quincy, Mass., home. AP PhotoCharles Krupa
How to Set Up a Red Lion Pax2D
6 Tips to Help You Save Money on BeautyProducts
How to Prepare for a Catastrophe
Why Some Women Have So Much More Trouble Getting Pregnant Than Others
How Much of Your Tax Refund Should You Really Spend
Taking the tube to work is about to get a whole lot worse
The Best Pieces On The High Street This Season
7 Surprisingly Healthy Mexican Recipes for Cinco de Mayo
Merriam-Webster Announces Feminism Is the 2019 Word of the Year
Is White Rice Healthy 7 Ways It Can Help You Out