使用下面的代码,我得到 workingSetSize 以字节为单位。
@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='Notepad.exe' get ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9P]" "') do (
set "line=%%A"
echo !line:~0,-1!
))>out.txt
我可以在上面的代码中以 KB 获得这个内存吗?
编辑1:
我已将代码修改为:
@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='Notepad.exe' get ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9P]" "') do (
set "mem=%%B"
set /a mem=mem/1024
echo %%A !mem!
))>out.txt
并获得输出为:
ProcessId WorkingSetSize 0
5816 9142272 0
5246 5673423 0
但我不想要那些 0,我只需要如下所示:
ProcessId WorkingSetSize
5816 9142272
5246 5673423
编辑2
如果我使用下面的代码:
@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,2" %%A in ('"wmic process where Caption='Notepad.exe' get ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9P]" "') do (
set "mem=%%B"
set /a mem=mem/1024
echo %%A !mem!
))>new.txt
然后输出如下:
ProcessId 0
5216 6112
1152 6524