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
)
精彩评论