Pause for n seconds

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Pause for n seconds

#1 Post by scienceguru1.bat » 16 Mar 2011 17:10

Does anyone know of a way to have the script pause for n seconds? thanks.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Pause for n seconds

#2 Post by aGerman » 16 Mar 2011 17:16

Often used: PINGing the own machine:

Code: Select all

ping -n 11 localhost>nul

... for a delay of 10 seconds (one more pings than seconds).

Regards
aGerman

scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: Pause for n seconds

#3 Post by scienceguru1.bat » 16 Mar 2011 17:18

How do the variables work?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Pause for n seconds

#4 Post by aGerman » 16 Mar 2011 17:21

Don't get it. There is no variable :?

scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: Pause for n seconds

#5 Post by scienceguru1.bat » 16 Mar 2011 17:50

How to adjust the wait.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Pause for n seconds

#6 Post by aGerman » 16 Mar 2011 18:23

As I wrote: "one more pings than seconds".
number of pings = number of seconds + 1

Code: Select all

@echo off &setlocal
set /p "x=Enter the number of seconds: "

set /a x+=1

echo delay start %time%
ping -n %x% localhost>nul
echo delay end %time%

pause>nul

It takes approx. 200ms to call ping.exe, thats why the delay is a little longer.

Regards
aGerman

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Pause for n seconds

#7 Post by !k » 17 Mar 2011 09:53


scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: Pause for n seconds

#8 Post by scienceguru1.bat » 17 Mar 2011 13:36

thanks, everyone. i'll test it when i can get on my computer. it should work.

scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: Pause for n seconds

#9 Post by scienceguru1.bat » 17 Mar 2011 17:50

Thanks everyone, it works :D

Post Reply