Thursday, 19 September 2013

CMD how to use if and tasklist with find /C

CMD how to use if and tasklist with find /C

Anyone knows how to use IF and tasklist with find /C. I want to compare
running instances or certain application to predefined number.
Application name= test.exe
number of instances that should run=2 (If there are less then do stuff
else report OK)
Here is my doo-bey-doo so far:
tasklist /FI "IMAGENAME eq test.exe" | find /I /C "test.exe"
This works great. I get the correct figure of running instances. But when
I put it into IF sentence in a BATCH file that's where the hell breaks
loose. So where I go wrong here?
if tasklist /FI "IMAGENAME eq test.exe" | find /I /C "test.exe" EQU 2 :
ECHO OK
ELSE ( GOTO doStuff )
:doStuff

No comments:

Post a Comment