开发者

Batch Files - If output <=2 do this, if output >2 do that (Perform action dependent on output)

I am tryin开发者_开发知识库g to perform an action depending on this statements output:

wmic process where name="test.exe" | find "test.exe" /c

if the output is <=2 do echo two or less

if the output is >2 do echo more than two

How could this be achieved?


set them to variables then compare also you want switches before the search string =D

FOR /F "tokens=2 USEBACKQ delims=:" %%F IN (`command ^| find /C "test.exe"`) DO (
  SET var=%%F
)

IF %var% LEQ 2 ECHO Two or Less
IF %var% GTR 2 ECHO More than Two

EDIT: (for Jeb <3)

FOR /F "tokens=2 USEBACKQ delims=:" %%F IN (`command ^| find /C "test.exe"`) DO (
  SET var=%%F
)

IF %var% LEQ 2 (
 ECHO Two or Less
) ELSE ( 
 ECHO More than Two
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜