Computing.Net > Forums > Programming > Batch file using FIND & IF ERRORLEV

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file using FIND & IF ERRORLEV

Reply to Message Icon

Name: Tollas
Date: March 26, 2008 at 10:08:38 Pacific
OS: XP/2003
CPU/Ram: Various
Product: Windows
Comment:

Attempting to create a batch file that will search data1.txt, then data2.txt for the string "login failed". When found, it will report the first occurance or report if none found.
Issue occurs when running program. Even if data1 is empty, it still reports as if "login failed" found.

@echo off
FIND /i "login failed" data1.txt
IF ERRORLEVEL 0 GOTO ERROR1
FIND /i "login failed" data2.txt
IF ERRORLEVEL 0 GOTO ERROR2
GOTO NOERROR

:ERROR1
ECHO Error in data1
GOTO END

:ERROR2
ECHO Error in data2
GOTO END

:NOERROR
ECHO No errors found
GOTO END

:END
PAUSE



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: March 26, 2008 at 10:19:52 Pacific
Reply:

You have to code

@echo off
FIND /i "login failed" data1.txt
IF NOT ERRORLEVEL 1 GOTO ERROR1
FIND /i "login failed" data2.txt
IF NOT ERRORLEVEL 1 GOTO ERROR2
GOTO NOERROR

as the condition is satisfied if errorlevel is equal or greater the value expressed, so in your script it is always true, found or not.


0

Response Number 2
Name: Tollas
Date: March 26, 2008 at 11:13:10 Pacific
Reply:

Thank you! That fixed it!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file using FIND & IF ERRORLEV

Batch File to find files www.computing.net/answers/programming/batch-file-to-find-files/17076.html

Batch file to find drive letter www.computing.net/answers/programming/batch-file-to-find-drive-letter/15558.html

batch file to find and copy www.computing.net/answers/programming/batch-file-to-find-and-copy/9236.html