1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unexpected "Variable loop" in IF condition

Discussion in 'Support' started by Mike Hall, Sep 9, 2016.

  1. Mike Hall

    Joined:
    Sep 9, 2016
    Messages:
    3
    Likes Received:
    0
    I'm wanting to check the first word of the TCC window (tab) title. From the prompt I can:

    > echo "%_wintitle"
    "nibuild (16.1.0f4) - mx Build Services"

    > echo "%@word[0,%_wintitle]"
    "nibuild"


    Which is what I expect. Then I try this as a conditional:

    > if "%@word[0,%_wintitle]" == "nibuild" echo yes
    TCC: Variable loop
    Usage : IF [/I] [NOT] condition [.AND. | .OR. | .XOR. [NOT] condition ...] command


    Which is not what I expect.

    What I ended up doing to make this work is:

    > setlocal & set thetitle=%@word[0,%_wintitle] & if "%thetitle" == "nibuild" echo yes & endlocal

    And this does work for me.

    So I'm posting this to find out if this is a bug or if I'm doing something wrong with my conditional.

    Thanks!
     
  2. Mike Hall

    Joined:
    Sep 9, 2016
    Messages:
    3
    Likes Received:
    0
    Forgot to mention, I'm using: TCC 20.00.17 x64 Windows 7 [Version 6.1.7601]
     
  3. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    Seems like a specific problem with %_wintitle:
    Things go also wrong with command: if "%_wintitle" == "nibuild" echo yes (TCC crashes!), whereas
    if "%_dos" == "WINDOWS7" echo yes gives me yes.

    BTW: also a crash with %_WINFGWINDOW, but with related variable functions like @WINEXENAME and @WINTITLE no problems detected...

    Anyway: nothing wrong with your conditional as far as I can tell.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
    WAD.

    Think about what you're doing here -- you're trying to expand the window title, which contains the command line you're trying to execute. So %_wintitle is expanded to:

    TCC Prompt - if "%_wintitle" == "nibuild" echo yes

    which (since you didn't turn off nested variables) is expanded to:

    TCC Prompt - if "%_wintitle" == "nibuild" echo yes

    ad infinitum. You can either turn off the window title updates (OPTION / Startup / Update Titles), turn off nested variables, or find an approach that doesn't reference itself.
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
    Can't reproduce the crash, but I get either a variable loop error or an out of memory error, as expected. (See my previous message.)
     
  6. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    Wow, never thought of that! (coming from CMD...)


    No we have the knowledge (thanks for explaining!), it is quite easy to by-pass:

    Code:
    title nothing
    call if "%@word[0,%_wintitle%]" == "nothing" echo JA
    or:
    call if "%_wintitle%" == "nothing" echo %_wintitle
    
    Gives you JA resp. nothing

    BTW: call if "%@word[0,%_wintitle%]" == "nothing" set CHECK=JA will also work; the CHECK variable survives the call-statement.
     
  7. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    With command if "%@word[0,%_wintitle]" .... I get the Variable loop error, with command if "%_wintitle" .... I get a crash.
    Well, crash is maybe not the right word: 1 CPU around 100% (I guess the one where this %_wintitle thread runs) and TCC-shell completely non-responsive. A taskkill is the only way out.

    Might be my setup, though; I'm ehh experimenting with TCMD (installing and running without administrative rights. Everything seems to work, but this might be the cause of the "crash")
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,027
    Likes Received:
    84
    It's not crashing, it's working its way up to running out of memory. But on an x64 system, that can take a LONG time, since TCC variables no longer have a length limit.
     
  9. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    Yeah, that's way beyond my patience :-) Thanks for feedback!
     
  10. Mike Hall

    Joined:
    Sep 9, 2016
    Messages:
    3
    Likes Received:
    0
    Wow. Ok. I feel dumb. My title is usually set to a project name so I can easily see from the tab name which project it is. That name ends up being longer than the max tab size, so I don't see the tab itself expanding and shrinking like it does when I don't set the title at all. But now that you mention this feature, I see that I can hover the mouse over the tab and see the added text of the running command.

    Now it makes perfect sense why I'm getting this error. Thanks for the clarification.

    My "work around" was already using setlocal / endlocal, so I'll keep that and add "setdos /x-4" so I can simplify my conditional and not use a temporary variable.

    Thanks again for the quick response!
     
  11. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    355
    Likes Received:
    8
    I think that's a good decision; the CALL <internal command> isn't really supported anyway (try CALL for .... : no luck). It just happens to work in this case.

    EDIT: My bad. Of course you have to replace %x with %%x in a call statement. Then it will run (but still unsupported ...)
     

Share This Page