I have found the need to report an error level to a program that calls batch scripts.
The script will create a CSV log file that I would like to check in order to display whether the script was run successfully.
What I would like to say is something like
IF NOT FIND "[ERR" "test.csv"
or to say, that if the string "[ERR"
is not in the output ERRORLEVEL = 0 ELSE ERRORLEVEL = 1
Hope this makes sense. I'm sure it is simple but setting error levels seems to be a royal pain in the a$se!
Note that the IF command has the logic that it returns true if ERRORLEVEL is greater than or equal to the following number! So
IF ERRORLEVEL 0 (...
returns true for all FIND commands. What you need if you only want to test if a phrase is in a file:
find "string" "test.txt" > NUL & IF NOT ERRORLEVEL 1 ECHO String was found
Took me ages to work that out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With