@echo off
set IP=192.168.0.1
set set_sd=0
set res_sd=1
set error_num=0
set DATE=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,8%
set DAY=%date:~0,4%-%date:~5,2%-%date:~8,2%
:ping_passed
ping 127.1 -n 10 >nul
ping -w 1000 -n 3 %IP%|find "TTL"
set DATE=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,8%
set DAY=%date:~0,4%-%date:~5,2%-%date:~8,2%
::update the date and time.
echo %DATE% Please keep this window runing and don't close it!
if %error_num%==5 goto Set_shutdown
if %errorlevel%==0 goto Res_shutdown
if %errorlevel%==1 goto Ping_failed
:Ping_failed
set /a error_num +=1
echo %DATE% The ping is failed, error=%error_num%
echo %DATE% The ping is failed, error=%error_num% >>E:\log\%DAY%.txt
goto ping_passed
以上为自己写的部分bat批处理代码,打开运行超过一天之后, %DATE%命令不能获取的日期还是bat文件打开的日期,%time%是对的。重新Win+R运行cmd,输入date命令获取的日期是当前的日期,没有问题。
为什么bat持续运行一天以上%date%命令获取的日期不更新呢?请指教。