0

使用下面的代码,我得到 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 
4

1 回答 1

1

如果数字始终小于 2 GB,那么您可以使用它

@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,2" %%A in ('"wmic process where Caption='HsvDataSource.exe' get  ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9]" "') do (
set "mem=%%B"
set /a mem=mem/1024
echo PID:%%A %%B=!mem! KB
))>out.txt

上面EDIT2的解决方案

@echo off
setlocal enabledelayedexpansion
>new.txt echo ProcessId  WorkingSetSize
(For /F "tokens=1,2" %%A in ('"wmic process where Caption='Notepad.exe' get   ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9]" "') do (
set "mem=%%B"
set /a mem=mem/1024
echo %%A !mem! 
))>>new.txt
于 2013-10-23T09:37:06.407 回答