回复 4# pcl_test
一语惊醒梦中人,还是自己学艺不精。
多谢!
setlocal EnableDelayedExpansion 开启变量延迟后,需要使用“!”来引用变量。
修改后的代码:
--------------------------------------------------------------------代码开始(本行非代码行)--------------------------------------------------------------------- @ECHO OFF & setlocal EnableDelayedExpansion
- TITLE test
-
- ECHO ##***************************************************************************## > log.txt
- REM BAT运行开始时间记录
- set nowtime=%time: =0%
- ECHO %date% %nowtime:~,8% >> log.txt
- ECHO .>> log.txt
-
- SET COUNT=0
- FOR %%i IN (1,2,3,4,5,6,7,8,9,10) DO (
- SET /A COUNT+=1
- ECHO No.!COUNT! [%%i] >> log.txt
-
- REM 处理开始时间记录
- set nowtime=!time: =0!
- ECHO !date! !nowtime:~,8! >> log.txt
-
- REM 暂停处理
- PAUSE
-
- REM 处理结束时间记录
- set nowtime=!time: =0!
- ECHO !date! !nowtime:~,8! >> log.txt
- )
- ECHO . >> log.txt
-
- REM BAT运行结束时间记录
- set nowtime=%time: =0%
- ECHO %date% %nowtime:~,8% >> log.txt
- ECHO ##***************************************************************************## >> log.txt
- PAUSE>nul
- @ECHO ON
复制代码 --------------------------------------------------------------------代码结束(本行非代码行)--------------------------------------------------------------------
修改后实行结果:
--------------------------------------------------------------------结果开始(本行非结果行)--------------------------------------------------------------------- ##***************************************************************************##
- 2015/07/29 13:23:24
- .
- No.1 [1]
- 2015/07/29 13:23:24
- 2015/07/29 13:23:27
- No.2 [2]
- 2015/07/29 13:23:27
- 2015/07/29 13:23:29
- No.3 [3]
- 2015/07/29 13:23:29
- 2015/07/29 13:23:30
- No.4 [4]
- 2015/07/29 13:23:30
- 2015/07/29 13:23:32
- No.5 [5]
- 2015/07/29 13:23:32
- 2015/07/29 13:23:33
- No.6 [6]
- 2015/07/29 13:23:33
- 2015/07/29 13:23:35
- No.7 [7]
- 2015/07/29 13:23:35
- 2015/07/29 13:23:37
- No.8 [8]
- 2015/07/29 13:23:37
- 2015/07/29 13:23:39
- No.9 [9]
- 2015/07/29 13:23:39
- 2015/07/29 13:23:40
- No.10 [10]
- 2015/07/29 13:23:40
- 2015/07/29 13:23:41
- .
- 2015/07/29 13:23:41
复制代码 ##***************************************************************************##
--------------------------------------------------------------------结果结束(本行非结果行)-------------------------------------------------------------------- |