批处理文件 - 如果输出< = 2执行此操作,如果输出> 2执行此操作(执行操作取决于输出)

时间:2011-06-15 14:27:27

标签: windows batch-file

我正在尝试根据此语句输出执行操作:

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

如何实现这一目标?

1 个答案:

答案 0 :(得分:2)

将它们设置为变量,然后在搜索字符串= 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

编辑:(对于Jeb&lt; 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
)