Quitting script with an error code denoting a failure

Comments

1 comment

  • jvb

    Just put an exit /B 1 at the end of process found.

    Personally I would probably just split these up into steps in pdq and do just below in step 1

    set EXE=Program.exe
    FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% exit /B 1

    Then assuming you don't have 1 as a success code, it would stop there. Alternatively, you could do

    tasklist | findstr Program.exe

    Where findstr will return 0 (true) if Program.exe is found and 1 if not (so set 1 as success code instead of 0 in this case).

     

    1
    Comment actions Permalink

Please sign in to leave a comment.