【发布时间】:2014-06-16 23:58:03
【问题描述】:
我正在尝试编写一个批处理文件,该文件需要花费命令的时间并将其转换为小时、分钟和秒。
这是我得到的:
@echo off
set /a sec=0
set /a min=0
set /a hrs=0
for /f %%G in ('ping localhost -n 100 >nul') do (
ping localhost -n 1 >nul
set /a sec+=1
if %sec%==60 (
set /a min+=1
set /a sec=0
)
if %min%==60 (
set /a hrs+=1
set /a min=0
)
)
echo Time taken: %hrs%:%min%:%sec%.
我不断收到“),此时是出乎意料的。”错误。 FOR 循环确实有效,问题只是 IF 语句。
我尝试使用 EQU 运算符并添加引号无济于事。有人可以帮忙吗?
另外,我在某处读到集合运算符在 IF 语句下可能不起作用 - 这是真的吗?
【问题讨论】:
标签: batch-file if-statement environment-variables set-operations