This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Silly that the command would even be accepted... that's in no way a valid IP address. But apparently, the Windows ping command treats anything shorter than four digits as an acceptable IP octet...
–
MassimoSep 26 '12 at 19:10

It should be noted that while the choice command is waiting 5 seconds for input, the timer gets reset each and every time the user presses a key. So it is possible that your batch file will never exit this choice step. Therefore it is also impossible to guarantee that the routine will only wait 5 seconds -- it could be longer because of a key press.
–
Richard WestJul 9 '09 at 16:53

1

At first I thought you were wrong. I'm using Vista and 'choice' works just fine, but upon further investigation it seems that 2000/XP/2003 didn't have it by default. For some reason they brought it back with Vista/2008.
–
ThatGraemeGuyJul 12 '09 at 11:04

3

timeout also is only available from Vista onwards.
–
JoeyFeb 5 '11 at 0:19

3

Sorry for the downvote, but that's just another kludge, and timeout is there exactly for this purpose.
–
MassimoSep 26 '12 at 19:11

The correct way to do this is to use the timeout command, introduced in Windows 2000.

To wait 30 seconds:

timeout /t 30

The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak, which effectively ignores anything the user may press, except an explicit CTRL-C:

timeout /t 30 /nobreak

Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to NUL:

The ping one (above) is a good one- but only works if connected to a network.

A bit of script that will delay is below:

@echo off

set /a secondsend=%TIME:~6,2%+10

if %secondsend% GTR 59 set /a secondsend=secondsend-60

:waithere

if %TIME:~6,2% NEQ %secondsend% goto waithere

This will pause from between 9-10 seconds (the first second isn't accurate due to using the TIME command- and it could be halfway through a second before you begin).

If works by setting 'secondsend' to the current second of the pc clock, then adding 10 to it (the delay). If it's greater than 59 taking 60 off as it's wrapped around to next minute. Then there is a loop which checks the current second with 'secondsend'- once they match the script continues.

If you want to delay by a different period 2-59 then alter the 10 in the second line (I say 2-59 as the first second might not be a full second, so 2 could be say, 1.2 seconds for example).

Sorry it's so longwinded but thought I'd explain how the routine works.

Nice. Beware, though, that this is a tight look which might consume much of the processing time on the core it's running on, right?
–
bzlmNov 17 '09 at 8:05

Yes you're right bzlm- much of the spare capacity of the CPU seems to get used up, though other programs can still run ok and 'take some back'. Just been testing it. Shame that. I wonder if anything can be inserted into the loop to avoid this? This is the beauty of the proper 'sleep' command, it just counts clock cyces and does not hog the cpu processes, allowing better resources use. Pity 'sleep' isn't a built in function. Mark H.
–
Mark HNov 17 '09 at 20:06

I have yet to see a recent version of Windows that didn't have at least IPv4 installed. ping -n 6 127.0.0.1 works fine to sleep 5 seconds, even if no network interface has a connection.
–
JoeyFeb 5 '11 at 0:21