变量延迟
使用情况:当在复合命令(例如循环语句)中使用变量时,需要使用变量延迟。
setlocal enabledelayedexpansion
for /L %%l in (1,1,10) do (
set/a NUM+=%%l
echo !NUM!
)
for循环
参数列表:
-/D:列举循环
for /D %%d in (item1,item2,item...) do ()
-/F:文本循环
for /F "skip=%numSkipLine% tokens=%numTokenColStart%-[%numTokenColEnd%] delims=%falgdelims%" %%f in (command/text/file...) do ()
-/R:
-/L:逻辑循环
for /L %%l in (%start%, %step%, %end%) do ()
检测CPU占用率
echo off
for /f "skip=1 tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value') do (
set/a CPU+=%%a)
set/a CPU/=3
echo %CPU%