Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Unexpected "Variable loop" in IF condition

Sep
3
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!
 
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.
 
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.

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.
 
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.

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.)
 
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:
......
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.

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.
 
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.)

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")
 
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")

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.
 
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!
 
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.

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 ...)
 

Similar threads

Back
Top