WMIC的输出是unicode!
可以通过将值传递到另一个<CR>
循环中来删除结尾的FOR /F
。
这还会删除幻影的“空白”行(实际上是<CR>
)
@echo off
If Exist testMEMORY.txt Del testMEMORY.txt
:loop
(
@echo %time% %date%
for /f "skip=1 delims=" %%a in ('wmic OS get FreePhysicalMemory /Value') do (
for /f "delims=" %%b in ("%%a") do (
echo %%b
)
)
)>>testMEMORY.txt
timeout /t 10 /nobreak>nul
goto loop
所以,我得到testMEMORY.txt
这样的结果:
15:32:19.02 04/11/2019
FreePhysicalMemory=528592
15:32:29.19 04/11/2019
FreePhysicalMemory=530804
15:32:39.14 04/11/2019
FreePhysicalMemory=531156
15:32:49.21 04/11/2019
FreePhysicalMemory=530968
15:32:59.16 04/11/2019
FreePhysicalMemory=531936
15:33:09.23 04/11/2019
FreePhysicalMemory=530376
15:33:19.18 04/11/2019
FreePhysicalMemory=524980
15:33:29.16 04/11/2019
FreePhysicalMemory=521816
15:33:39.21 04/11/2019
FreePhysicalMemory=465820
15:33:49.17 04/11/2019
FreePhysicalMemory=461312
15:33:59.17 04/11/2019
FreePhysicalMemory=385172
15:34:14.21 04/11/2019
FreePhysicalMemory=529800
15:34:24.13 04/11/2019
FreePhysicalMemory=541064
,
由于您的命令输出几乎没有机会包含UTF-16之外不可用的字符,因此我将提供此简单的修复程序,我认为这将提供可接受的输出。
:Loop
@>"testMEMORY.txt" ( Echo %TIME% %DATE%
WMIC OS Get FreePhysicalMemory /Value|Find "=")
@Timeout 10 >NUL
@GoTo Loop
本文链接:https://www.f2er.com/3166574.html