I am writing a small BAT file where it will search for "FAIL" Keyword followed by PASS - if none is found then take it as an error:
echo
set "topLevel=%cd%"
If [%1]==[] exit /B 1
If [%2]==[] exit /B 1
If [%3]==[] exit /B 1
If [%4]==[] exit /B 1
findstr /? >NUL 2>&1 || exit /B 1
set "arg1=%1"
set "arg2=%2"
set "arg3=%3"
set "arg4=%4"
set /a errno=0
if not exist %arg3% exit /B 1
if not exist %arg2%\%arg1% exit /B 1
set "logfile=%arg1:.=_%"
copy /y/v %arg2%\%arg1% %arg3%\%arg4%.%logfile%.res || exit /B 1
findstr /I /C:"FAIL" /I /C:"UNKNOWN" %arg3%\%arg4%.%logfile%.res 
if %errorlevel% EQU 0 (
    set /a errno=2
) ELSE (
    REM MAKE SURE THAT THE SCRIPT DID NOT CRASH HENCE NEITHER PASS OR FAIL WILL BE LISTED
    findstr /I /C:"PASS" %arg3%\%arg4%.%logfile%.res  
    if %errorlevel% NEQ 0 (
    set /a errno=2
    )
)  
cd %topLevel%
exit /B %errno%
When I run with sample data I get below output:
..............................................
    C:\agent\_work\30\s1>copy /y/v C:\output\test.log C:\agent\_work\30\s1\tttt.test_log.res   || exit /B 1
            1 file(s) copied.
    C:\agent\_work\30\s1>findstr /I /C:"FAIL" /I /C:"UNKNOWN" C:\agent\_work\30\s1\tttt.SystemWalk_log.res
    C:\agent\_work\30\s1>if 1 EQU 0 (set /a errno=2 )  ELSE (
    REM MAKE SURE THAT THE SCRIPT DID NOT CRASH HENCE NEITHER PASS OR FAIL WILL BE LISTED
     findstr /I /C:"PASS" C:\agent\_work\30\s1\tttt.test_log.res
     if 1 NEQ 0 (set /a errno=2 )
    )
    PASSED
    PASSED
    PASSED
    PASSED
    PASSED
    C:\agent\_work\30\s1>cd C:\agent\_work\30\s1
    C:\agent\_work\30\s1>exit /B 2
    C:\agent\_work\30\s1>echo %ERRORLEVEL%
    2
Actually cause it has found "PASS" string and no "FAIL" ones - so the error level should be 0 - how can I fix the issue?