Reputation: 177
Why does this:
for /f "tokens=5 delims=<>" %%G in ('findstr /C:"<a href=\"register\">" "index.html"') do echo %%G
give an errorlevel 1 while this
findstr /C:"<a href=\"register\">" "index.html"
gives an errorlevel 0?
The first code gives me the string I'm looking for. The second one gives the line of text where the string is in. I need the first code to give me an errorlevel 0 because it returned no errors as far as I know. What am I doing wrong?
Upvotes: 0
Views: 641
Reputation: 67226
The for
command can not set the ERRORLEVEL to 1; it just preserve the same value it had before. I suggest you to set the ERRORLEVEL to 0 before the for
via this line:
ver > nul
You may review a full description of the ERRORLEVEL values set by all internal commands at What are the ERRORLEVEL values set by internal cmd.exe commands?
Also, you didn't said us how you are testing the ERRORLEVEL. If you are using if %ERRORLEVEL% ...
and this command is placed inside a code block, it may also be a Delayed Expansion related problem.
Upvotes: 1