0

Im using ping to create a delay in my batch file, but there seems to be quite a big limit on how short you can make the ping delay.

ping -n 1 -w 1 1.1.1.1
this will wait for maybe 500ms

ping 127.0.0.1
this will wait for maybe 100ms

So is there a way to get an even smaller delay?

This is on XP, so "timeout" isnt enabled

Supercreature
  • 441
  • 6
  • 25
  • possible duplicate of [delay a batch file in under a second?](http://stackoverflow.com/questions/29732878/delay-a-batch-file-in-under-a-second) – dbenham May 15 '15 at 16:39

1 Answers1

0

You can do this in XP with Windows scripting, by creating a VBScript file millisleep.vbs that looks like this (with decent error checking built in):

if wscript.arguments.count <> 1 then
    wscript.echo "millisleep.vbs: Not enough arguments"
    wscript.quit 1
end if

delay = wscript.arguments(0)
if not isnumeric(delay) then
    wscript.echo "millisleep.vbs: " & delay & " is not numeric"
    wscript.quit 1
end if

wscript.sleep delay

Then, from your own script, you can use something like this to get a quarter-second delay:

cscript //nologo millisleep.vbs 250
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • A minor problem with this is it is not very accurate due to CSCRIPT start-up and compilation times. See my [SLEEP.BAT](http://stackoverflow.com/a/29879492/1012053) for a hybrid JScript/batch solution that is accurate to within 10 msec as long as delay exceeds the minimum of ~50 msec. – dbenham May 15 '15 at 16:50