方法一:ping
缺点:时间精度为1秒,不够精确
| 12
 3
 
 | @echo off@ping 127.0.0.1 -n 6 >nul
 start gdh.txt
 
 | 
方法二:vbs start /wait
缺点:生成临时文件
有点:时间精度为0.001秒,精度高
| 12
 3
 4
 5
 
 | @echo offecho wscript.sleep 5000>sleep.vbs
 start /wait sleep.vbs
 start gdh.txt
 del /f /s /q sleep.vbs
 
 | 
方法三:vbs cscript
| 12
 3
 4
 5
 
 | @echo offecho wscript.sleep 5000>sleep.vbs
 @cscript sleep.vbs >nul
 start gdh.txt
 del /f /s /q sleep.vbs
 
 | 
方法四:choice
ssh过去有问题,停不下来
优点:时间精确,CPU占用低,是最佳选择
CHOICE:[/C[:]按键表] [/N] [/S] [/T[:]选择值,秒数] [显示文本]
其中,/C表示可选则的按键,/N表示不要显示提示信息,/S表示大小写字符敏感方式,/T表示若在批定的时间内没有选择的话,自动执行/C中定义的某个选择值。显示文本是CHOICE命令执行时的提示信息。选择结果将用ERRORLEVEL值来表示
| 12
 3
 
 | @echo offchoice /t 5 /d y /n >nul
 start gdh.txt
 
 | 
方法五:for+set+if,时间精度为0.01秒
缺点:CPU占用高,语句过长,不常用
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 
 | @echo offsetlocal enableextensions
 echo %time%
 call :ProcDelay 500
 echo %time%
 start gdh.txt
 :ProcDelay delayMSec_
 setlocal enableextensions
 for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
 :_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
 
 |