2024年6月3日发(作者:)
1、暂停(Pause)、延迟(Delay)、等待(Wait)、睡眠(Sleep)
1)for+set+if,时间精度为0.01秒,适用平台为WinNT/2K/XP/2003。
利用for解析变量%time%并存为两个时间点%start%和%now%,再利用set /a计
算两个时间点的时间差,最后用if判断时间差是否达到设定的暂停时间。
@echo off
setlocal enableextensions
echo %time%
call :ProcDelay 200
echo %time%
goto :EOF
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%")
start_=%%h%%i%%j%%k
do set
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set
now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS %1 goto _procwaitloop
endlocal & goto :EOF
2)VBS脚本中的sleep函数,时间精度为0.001秒,使用平台为Win9x/WinNT系列。
动态创建一个调用sleep()函数的VBS脚本,然后用Windows脚本宿主的命令行版
本cscript调用它。
@echo off & setlocal enableextensions enabledelayedexpansion
echo 2000 > %temp%tmp$$$.vbs
echo %time%
cscript //nologo %temp%tmp$$$.vbs
echo %time%


发布评论