Computing.Net > Forums > Disk Operating System > Delay in batch files w/o 3rd party

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delay in batch files w/o 3rd party

Reply to Message Icon

Name: Secret_Doom
Date: July 4, 2003 at 19:05:41 Pacific
OS: N/A
CPU/Ram: N/A
Comment:

I few days ago, a guy named Nathan tried to get a timed delay on a batch file. He stated that he had tried using the PING command, like this (in this case to wait 60 seconds):

ping 1.1.1.1 -n 60 -w 1000

Which specifies 60 pings with a timeout of 1000 miliseconds, firing against a non-existant (though valid) IP, so the whole timeout takes place. However, that won't work as intended, the delay time is way longer than 60 seconds and is pretty unpredictable.

I observed that such unexpected behavior seems to be caused by delays between different pings. So, I had an idea - use a single ping with the timeout being the whole wait time. We would do this, instead, to wait 60 seconds:

ping 1.1.1.1 -n 1 -w 60000

And guess what... It works just fine! So, let me analyse that new method:

Goods:
1. It doesn't require any 3rd party applications.
2. It will work under most versions of Windows.
3. It works properly as intended, taking a delay on the right amouth of time.

Bads:
1. It's a method restricted to batch files running under Windows. The application PING.exe won't work out of Windows.
2. When under Win98, CTRL+C and CTRL+BREAK don't seem to work during the delay, that is, the delay is not skipped. They do eventually take effect, but only after the delay has gone.

The undesired output from the command can be supressed by redirecting it to NUL:

ping 1.1.1.1 -n 1 -w 60000 > nul

That's it! Comments are welcome.
Thanks for Nathan for bringing this idea up.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 5, 2003 at 10:52:46 Pacific
Reply:

By the way, using CHOICE.COM to create a delay is a known method. However, such application is not avaliable on NT systems, which creates the need for another method.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 2
Name: Miskva
Date: July 9, 2003 at 15:46:26 Pacific
Reply:

Indeed, "choice" is the best thing for that .. but if it isnt on the system .. well, you could try and "steal" it from another OS .. I have seen similar stuff work

Otherwise; lend something from DOS his superior friend, called unix : sleep


0

Response Number 3
Name: Nathan
Date: July 23, 2003 at 17:58:02 Pacific
Reply:

Cant believe I never thought of that. well thanks for using my idea anyways


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Delay in batch files w/o 3rd party

How do iput wait or delays in batch files ? www.computing.net/answers/dos/-how-do-iput-wait-or-delays-in-batch-files-/4724.html

What does the % mean in batch files? www.computing.net/answers/dos/what-does-the-mean-in-batch-files/5925.html

Variables in batch files www.computing.net/answers/dos/variables-in-batch-files/12289.html