Code: Select all
for /l %%N in (0,1,9) do (
reg query "%key3%%%N"%valv3%" | findstr %%G 2>&1 && echo %%N || (find "ERROR:" && echo Break)
echo !errorlevel! & pause
)
There're 2 error types printed to console:
a) "End of search: 0 match(es) found" (its printed when the analyzed value doesn't match %%G)
b) "ERROR: The system was unable to find the specified registry key or value" (it's printed when the %key3%%%N or value "%key3%%%N"%valv3%" doesn't exist)
The code needs to break out of the inner FOR loop, when error b) occurs and the key doesn't exist. I can do it in a multilevel FOR, but when simplifying the structure, I seems to need analyzing the error text rather than ERRORLEVEL, since both above errors give the same ERRORLEVEL 1 value. The above code can't find "ERROR:" in the error output, it just goes through all 9 loops. What's the right way to analyze the error text here?