【语言-批处理】批处理延时启动程序

方式一、使用vbs脚本延时,精度0.001秒

echo off
rem 时间单位 - ms
echo wscript.sleep 2000>%~dp0\Sleep.Vbs
start /wait %~dp0\Sleep.Vbs
rem 程序路径
start osk.exe
del %~dp0\Sleep.Vbs
exit
echo off
rem 时间单位 - ms
echo wscript.sleep 2000>%~dp0\Sleep.Vbs
cscript %~dp0\Sleep.vbs >nul
rem 程序路径
start osk.exe
del %~dp0\Sleep.Vbs
exit

方式二、ping本地网络,精度1秒

echo off
rem 时间单位 - s
ping 127.0.0.1 -n 2 >nul
rem 程序路径
start osk.exe
exit

方式三、使用选择器暂停,精度1秒 

echo off
rem 时间单位 - s
choice /t 2 /d y /n >nul
rem 程序路径
start osk.exe
exit

 方式四、获取系统时间来延时,精度 0.01秒

echo off

setlocal enableextensions
echo %time%

rem 时间 0.01s
call :funDelay 200
echo %time%

rem 程序路径
start osk.exe

rem 延时函数
:funDelay delayTime
setlocal enableextensions

rem 获取开始时间,去掉冒号(:)和点(.)
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set myStartTime=%%h%%i%%j%%k

:_loopWaitDelay
rem 获取当期时间,去掉冒号(:)和点(.)
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set myCurTime=%%h%%i%%j%%k

rem echo 当前时间=%myCurTime%
set /a myWaitTime=%myCurTime%-%myStartTime%

rem echo 时间差=%myWaitTime%
rem 判断时间差是否小于第一个参数 %1= delayTime
if %myWaitTime% LSS %1 goto _loopWaitDelay

endlocal & goto :EOF


 

你可能感兴趣的:(语言-Python)