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

Batch file using FIND & IF ERRORLEV

Reply to Message Icon

Original Message
Name: Tollas
Date: March 26, 2008 at 10:08:38 Pacific
Subject: Batch file using FIND & IF ERRORLEV
OS: XP/2003
CPU/Ram: Various
Model/Manufacturer: 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


Report Offensive Message For Removal

Response Number 1
Name: IVO
Date: March 26, 2008 at 10:19:52 Pacific
Subject: Batch file using FIND & IF ERRORLEV
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: Tollas
Date: March 26, 2008 at 11:13:10 Pacific
Subject: Batch file using FIND & IF ERRORLEV
Reply: (edit)

Thank you! That fixed it!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file using FIND & IF ERRORLEV

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software