Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit status of tasklist in batch file?

I am executing following command in a label inside a batch file:

tasklist.exe /FI "USERNAME eq %USERDOMAIN%\%USERNAME%" /FI "IMAGENAME eq %1" /FI "PID eq %2" 2>nul && echo errorl:%errorlevel%

%1 is process running and %2 is its PID. Even if process and its PID matches or doesnt matches, I m getting "errorl:1" in o/p.

I am not sure whats wrong here. Any idea?

like image 432
user613114 Avatar asked Feb 11 '11 13:02

user613114


1 Answers

You could pipe tasklist through the find command and get an errorlevel off of it.

Example:

tasklist | find "firefox.exe"
echo Error level = %ERRORLEVEL%

REM If firefox is running, the errorlevel is set to 0
REM If firefox is not running, errorlevel is set to 1
like image 148
Bill Avatar answered Dec 14 '22 17:12

Bill