我一直在尝试执行批处理文件。我尝试的逻辑是,如果服务的内存(工作集私有)超过服务应该重新启动的特定值。
但是,当我尝试执行此bat文件时,我收到错误为无效动词:
@Echo OFF
SET "SERVICE=Themes"
SET /A "MAXUSAGE=401400"
SET /A "INTERVAL=5"
:LOOP
For /F %%P in ('wmic path Win32_PerfFormattedData_PerfProc_Process where Name="cmd" get WorkingSetPrivate /value ^| FINDSTR "[0-9]"') do (
IF %%P GTR %MAXUSAGE% (
Echo [%TIME:~0,8%] CPU Usage: %%P%% Reached the limit: %MAXUSAGE%%%
Echo Restarting %SERVICE% ...
SC STOP "%SERVICE%" 1>NUL
SC START "%SERVICE%" 1>NUL
Echo Service restarted.
) ELSE (
Echo [%TIME:~0,8%] CPU Usage: %%P%%
)
)
Ping -n %INTERVAL% Localhost >NUL
GOTO :LOOP `
我对这种类型的编码很陌生。任何指导都将不胜感激。
答案 0 :(得分:0)
这是一个基本的命令行,它应该为您指出问题的解决方法:
For /F "Skip=1 UseBackQ" %A In (`wmic path Win32_PerfFormattedData
_PerfProc_Process where "name='cmd'" get workingsetprivate`) Do @For %B In (%A) Do @Echo([%B]
UseBackQ是你的线索......