0

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?

zcalebz
  • 139
  • 1
  • 12

1 Answers1

1

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.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Please, tell us the cause! Specially if it is _not_ one of the ones mentioned: previous errorlevel=1 or delayed expansion problem... – Aacini Feb 07 '16 at 15:44
  • So the solution is to set the errorlevel to 0 before the `for` command as I indicated in my answer, right? In my opinion my answer gives the correct solution, so you should mark it as the right answer... – Aacini Feb 08 '16 at 05:05