bizarre and inconsistent behavior in batch script


  1. Posts : 425
    Windows 10
       #1

    bizarre and inconsistent behavior in batch script


    I have a file called tokens.txt. It is a utf-8 text file that contains a number for lines with name=value
    It is used extensively in a script I have written and works 99 times out of 100. Every now and then I come across an issue I haven't been able to solve in the last 3 years.

    values are like;

    Code:
    tanya=123456
    tanya_vpn=au657
    tanya_cache=f:\users\tanya\firefox
    test=abcdef
    fred=12345-12345-12345-12345
    The vpn line I have just added. It won't work. I get no result. The batch code is

    Code:
    for /F "Usebackq Tokens=1* delims==" %%a in ("%BasePath%\%tfile%") do IF /I "%%a"=="%USERNAME%_vpn" set VPNserv=%%b
    %tfile% = Tokens.txt.
    %basepath%=I:\PostInstall
    It's clearly finding the file because it's cycling through each line of the file.

    Yet, this line works;
    Code:
    for /F "Usebackq Tokens=1* delims==" %%a in ("%BasePath%\%tFile%") do IF /I "%%a"=="%USERNAME%" set uWord=%%b
    as does this;

    Code:
    for /F "Usebackq Tokens=1* delims==" %%a in ("%BasePath%\%tFile%") do IF /I "%%a"=="%USERNAME%_cache" set MozCache=%%b
    As I watch the execution of the script I see this line;

    Code:
    IF /I "Tanya_vpn" == "Tanya_vpn" set VPNserv=au657
    Windows does not consider this a match and does not set the VPNServ variable.

    I've deleted the line and retyped it, in case there was some obscure non-printable character in there. I've tried using a dash instead of an underscore, but the cache entry works. I've put it as the first line and the last line in the file. Nothing works.

    It's bizarre. I can't figure out what's causing the problem.
      My Computer


  2. Posts : 1,211
    Windows 10
       #2

    Well its a IF evaluation so if it not working then that means it is not finding the required condition or the var is empty.
      My Computer


  3. Posts : 425
    Windows 10
    Thread Starter
       #3

    That's the problem, it is seeing the matching condition. It just doesn't see Tanya_vpn=Tanya_vpn as being a match, and it's picking up the resultant value of au657, so it's reading the file properly.

    As you can see from the original post, the comparitor is not empty - it contains my name. And the comparitee is there as well (sorry, making up new words).

    This is not contained within an IF ( .. ) block, so it's not a delayedexpansion issue either.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:31.
Find Us




Windows 10 Forums