Ok, this is an extract of some code I have been writing. It's purpose is to check if there are characters entered, ie not blank or any number of spaces. I tried using `findstr /r "[^a-z,0-9]"` for characters and using || if no characters were found but I couldn't get it to work. Anyway, this really has me confused...
@echo off
set /a c=1
:1
rem Below line shows status of echo.
echo
echo LOOP: %c%
set string=
set /p string=
echo %string% | findstr /I /c:"ECHO is on." >nul && echo ECHO IS ON WAS FOUND
rem BELOW LINE FOR COMPARISON, NOT IN MY CODE
echo %string% | findstr /I /c:"ECHO is off." >nul && echo ECHO IS OFF WAS FOUND
pause >nul
echo.
set /a c+=1
goto 1
Now as you can see, the echoed string variable, (which if blank or spaces should return "ECHO is off."), is piped to the findstr command. Which with case-insensitivity and searching for the phrase "ECHO is on." (Does not work with off). Now you'd assume that entering no or only blank characters would make this return nothing, as the string "ECHO is off." should have been found as 'echo' is the same as 'echo '.
ECHO is off.
LOOP: 1
STRING=test
ECHO is off.
LOOP: 2
STRING=next line blank ""
ECHO is off.
LOOP: 3
STRING=
ECHO IS ON WAS FOUND
ECHO is off.
LOOP: 4
STRING=next line spaces " "
ECHO is off.
LOOP: 5
STRING=
ECHO IS ON WAS FOUND
Of course if you type "ECHO is on." as the input it is found. Though why is findstr finding echo is on, on blank entries when echo is clearly off?