Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Weird Batch File Behaviour.  (Read 2260 times)

0 Members and 1 Guest are viewing this topic.

DeltaSlaya

    Topic Starter


    Apprentice
  • Google
    Weird Batch File Behaviour.
    « on: August 15, 2007, 02:24:39 AM »
    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...

    Quote
    @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    '.

    Quote
    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?
    System specs:
    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
    ASUS Striker Extreme
    XFX 8600GT XXX Edition
    2x 1gB Corsair XMS2 DDR2-800
    Seagate Barracuda 320gB SATA
    Raidmax Ninja 918 (520W ATXV2.0 PSU)
    -