我在使用以下批处理文件时遇到问题。首次运行时,它不会在文件中正确输出日期。在第一次运行时,我得到以下信息:
*Start of batch file ~4,2dt:~6,2dt:~2,2dt:~8,2dt:~10,2*
*End of batch file ~4,2dt:~6,2dt:~2,2dt:~8,2dt:~10,2*
在下次运行时它可以正常工作:
*Start of batch file 10/18/13 06:46*
*End of batch file 10/18/13 06:46*
需要注意的一点是,第一次运行时日志文件不存在,所以它可能与此有关?!?!?
这是我的批处理文件:
set logFile=C:\log.txt
echo %logFile%
REM Get the Start Date and Time and Parse it out
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set start=%dt:~4,2%/%dt:~6,2%/%dt:~2,2% %dt:~8,2%:%dt:~10,2%
ECHO Start of batch file %start% >>%logFile%
REM Run some procedure
REM Get the End Date and Time and Parse it out
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set end=%dt:~4,2%/%dt:~6,2%/%dt:~2,2% %dt:~8,2%:%dt:~10,2%
ECHO End of batch file %end% >>%logFile%
任何帮助/建议将不胜感激。