预期产出:
27%
C:\>wmic cpu get loadpercentage LoadPercentage 0
要么
C:\>@for /f "skip=1" %p in ('wmic cpu get loadpercentage') do @echo %p% 4%
以下在提升的命令提示符下在Windows 7 Ultimate上正常工作:
C:\Windows\system32>typeperf "\Processor(_Total)\% Processor Time" "(PDH-CSV 4.0)","\\vm\Processor(_Total)\% Processor Time" "02/01/2012 14:10:59.361","0.648721" "02/01/2012 14:11:00.362","2.986384" "02/01/2012 14:11:01.364","0.000000" "02/01/2012 14:11:02.366","0.000000" "02/01/2012 14:11:03.367","1.038332" The command completed successfully. C:\Windows\system32>
或者为快照:
C:\Windows\system32>wmic cpu get loadpercentage LoadPercentage 8
typeperf "\processor(_total)\% processor time"
在Win7上工作,你只需要从最后一个引用的字符串中提取百分比值。