Tag Archives: dos

Errorlevel and Findstr

ErrorLevel is not %ERRORLEVEL% . This is probably the first one you should read.

Next is the usage of the ERRORLEVEL statement. http://support.microsoft.com/kb/69576

 

The following table shows the effect of statement when writing your batch scriipt.

Statement Algebraic Equivalent.
IF ERRORLEVEL 5 … IF E = 5 OR E > 5 THEN …
IF NOT ERRORLEVEL 6 IF E < 6 THEN …

Here is a sample using findstr and error level. Findstr returns 0 if it successfully finds any occurrence.

findstr -sip Failed log.txt > NULLIF NOT ERRORLEVEL 1 (    echo Found.) else (    echo Not Found.)