Command Line "pause for n seconds" Command

  • Thread starter Thread starter Jay Somerset
  • Start date Start date
J

Jay Somerset

Is there any way to pause for a specified number of seconds in a CMD script?
Like the UNIX "sleep" command?
 
SET NumberOfSeconds=4
SET /A NumberOfSeconds+=1 >nul
ping -n %NumberOfSeconds% localhost>nul
echo I waited %NumberOfSeconds% seconds.
pause


That's the trick I've seen used often, anyway!
 
Oops. This would display the wrong number of seconds since I added 1 to the
input value. My bad. ;]
 
Ray at said:
Oops. This would display the wrong number of seconds since I added 1 to the
input value. My bad. ;]

No, Ray, what you did (add one second) was in fact correct.
To pause for 10 seconds, use 'ping -n 11 localhost > nul'.
 
Thanks Phil, but I was talking about my last line where I had:

echo I waited %NumberOfSeconds% seconds.

:]

--
Ray at work
Microsoft ASP MVP




Phil Robyn said:
Ray at said:
Oops. This would display the wrong number of seconds since I added 1 to the
input value. My bad. ;]

No, Ray, what you did (add one second) was in fact correct.
To pause for 10 seconds, use 'ping -n 11 localhost > nul'.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 
PERFECT! That was just the sort of "trick" I was looking for. I can now
create a SLEEP command based on PING.

Many Thanks,
Jay
 
Here is the completed SLEEP command, saved in WINNT...

@set /A snooze=1+%1
@ping -n %snooze% localhost > nul

Thanks agin, Ray.
 
Back
Top