How to pause or delay a .bat file for X amount of seconds?

Justin2135
Justin2135 used Ask the Experts™
on
Hello,

I know I can create a wait or delay by using the ping command but is there any other way to delay the .bat file with another command in XP?  I don't want to download the resource kit or any other download since this .bat file will be ran on other computers and I don't want to go through and download each time.  I've done some searching but haven't found anything yet.  

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can run a loop for i=1 to 2000 and then do a next i in a batch file and every 1000 is approx. 1 second of pause time .... it's not exact so if you need exact you'll need to look elsewhere, but it works if you just need to pause for a little bit for someone to read something or such ...

Commented:
There is a pause command that stops processing and requires user input (press any key...). Is that what you mean?

Author

Commented:
Would you mind providing the syntax on how to do that?  I have not been writing .bat files for very long so I'm still becoming familiar with it.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
I don't want the user to have to do anything.  Id rather it just wait for however many seconds or minutes I decide and then it will move on.
Steven CarnahanAssistant Vice President\Network Manager

Commented:
You can get the sleep command from the Windows 2003 Resource Kit:

http://malektips.com/xp_dos_0002.html
Commented:
Here's a code that will sleep for 10 seconds. With this you don't need the resourse kit.

@ECHO OFF
PING 1.1.1.55 -n 1 -w 10000 >NUL
start /d "C:\Program Files\Application\" Application.exe
for the PAUSE command you simply enter PAUSE on the line of the file where you want it to pause, and the user is prompted with 'Hit Any Key To Continue" automatically by the system, and until the user hits a key, the batch file is stopped at that point .... the FOR-NEXT Loop will allow it to pause for a bit of time as it takes time to count for the PC again the faster the PC the faster the count will go by, so experiment with how high you need to count to get the desired pause time ...
The PING command is another good way to pause again for every 1000 it is approx. 1 sec of pause time ...
Commented:
So this is the delay:
PING 1.1.1.55 -n 1 -w 10000 >NUL

The IP must not exist in the network for this to work.


where 5 is the number of second (1-99).

TYPE nul |CHOICE.COM /N /CY /TY,5 >nul

Open in new window

Author

Commented:
michaelaknight,

The syntax you listed didn't do anything.  It moved on to the next file without waiting the set amount seconds.

Commented:
Regarding my comment above: the numbers after -w is the number of milliseconds the delay should last.
And again, you don't need the resource kit for that delay.  
Steven CarnahanAssistant Vice President\Network Manager

Commented:
Taken from:   http://www.robvanderwoude.com/bht.php

Various methods

...insert a delay:
Use CHOICE (MS-DOS 6 and later, Windows NT/2000 with Resource Kit):

REM | CHOICE /C:YN /N /T:Y,10 >NUL

will delay execution for 10 seconds in MS-DOS.
TYPE NUL | CHOICE /C:YN /N /T:Y,10 >NUL

will do the same in Windows NT/2000 with CHOICE.EXE from the Resource Kit.
Use PING (MS-DOS with TCP/IP client, Windows 95/98/NT/2000):

PING 1.1.1.1 -n 10 -w 1000 >NUL

will delay execution for 10 seconds (10 times 1000 milliseconds), if and only if 1.1.1.1 is a non-existing IP address.
Use SLEEP or TIMEOUT (Windows NT/2000 with Resource Kit):

SLEEP 10

will delay execution for 10 seconds.

TIMEOUT 10

will wait for 10 seconds or continue when a key is pressed, whatever comes first.
Use KiXtart's SLEEP command (KiXtart must be installed):

>%TEMP%.\SLEEP.KIX ECHO SLEEP 10
KIX32 %TEMP%.\SLEEP.KIX
DEL %TEMP%.\SLEEP.KIX

will delay execution for 10 seconds.
looking closer... and i shouldv'e tested, but XP doesn't come with choice.com (at least not all builds do) ... wth ... Tried it in a virtual box and it worked (with pony's : correction [been a while]) but tried it on my workstation and choice isn't there... stoopid.

honestly pinging localhost is your cleanest option.
Steven CarnahanAssistant Vice President\Network Manager
Commented:
I understand michael, I ran into the "missing choice and sleep" issue many times.  That's why I found out where to get sleep. Ping is probably the best method as you say.  You can (hopefully) always be able to rely on it being there.  Who knows with MS though.  :)

My suggestion is either use ping or get sleep from a resource kit.

Commented:
pining localhost wont do it. It needs to be a non-existing IP.

Author

Commented:
I agree, Ping looks like my only choice without a resource kit.  I was mainly curious to see if there was an alternative way.  Thanks everyone!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial