How to make a batch file wait a split second?

I want the batch file to wait 0.5 or 0.25 seconds.
I already tried timeout /t 0.5 , but it does not work.

This is something like:
@echo off color a cls :top echo %random% timeout /t 0.5 echo %random% goto top

+5
source share
3 answers

Try the following: ping 1.1.1.1 -n 1 -w 250> nul 250 is the time in ms.

0
source

TIMEOUT only works in increments of whole seconds.

There are other third-party sleep executables that you can download.

Alternatively, you can use the Sleep method in VBScript. It takes values ​​in milliseconds. Here is a simple example (save it to SLEEP.VBS or any other name):

 ms = WScript.Arguments(0) WScript.Sleep ms 

Then in your batch file, call it so that it lingers for 0.5 seconds:

 CSCRIPT SLEEP.VBS 500 
+2
source

See this question for some useful information. To summarize, the use of ping to pause is limited to 500 ms or more. You cannot stop for 250 ms. The best solution is to use Windows Scripting Host - VB Script or JScript.

You can do this with batch / JScript hybrid to avoid having to call an external VBS script. Save this example with the .bat extension and try.

 @if (@CodeSection == @Batch) @then @echo off setlocal for /L %%I in (10,-1,1) do ( set /P "=%%I... "<NUL call :pause 250 ) echo Done. goto :EOF :pause <ms> cscript /nologo /e:JScript "%~f0" "%~1" goto :EOF @end // end batch / begin JScript hybrid code WSH.Sleep(WSH.Arguments(0)); 
+1
source

All Articles