Welcome!

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

SignUp Now!

_CMDLINE in TCEXIT (only sometimes)

May
12,834
163
It seems that sometimes _CMDLINE is set in TCEXIT and sometimes it's not. Here are four tries in a row. In two, the variable was set; in two it was not set.
upload_2016-5-9_22-53-5.png
 
And with this TCEXIT
Code:
v:\> type g:\tc19\tcexit.btm
ECHO %_CMDLINE
PAUSE
if I "X" the console, TCC takes 5 seconds to close, even if I dismiss the PAUSE immediately.

And "@EXIT" seems to always be set during TCEXIT, while "exit" is almost never set during TCEXIT.

And, with TCEXIT as above, if, in a newly opened console, I issue (by typing it)
Code:
echo foo & exit
TCC exits immediately (no TCEXIT).

OTOH, if I issue that command via history recall, TCEXIT is called (and _CMDLINE is usually not set).
 
I was a little off on my last comment. With this TCEXIT
Code:
BEEP 440 2
ECHO %_CMDLINE
PAUSE
If I type (enter at the command line)
Code:
echo foo & exit
I hear the beep and there's no pause; TCC exits immediately.
If, instead, I recall that same command from the history, the pause in TCEXIT happens.

It seems that just mentioning _CMDLINE screws up TCEXIT.
 
Then, with this TCEXIT
Code:
echo %_cmdline
pause

1. Why does is @exit command, when given on the command line, ALWAYS echoed by TCEXIT, while a simple "exit" is never echoed?
2. Why does "echo foo & exit", (typed, not history-recalled), cause the PAUSE not to be executed? The history-recalled version does it too if any changes were made to the recalled line ... adding a trailing space, for example, or simply moving the cursor in the recalled line without making a change.
 
This is pointless (we've had this conversation before) -- %_cmdline shows the content of the current command line, and you don't have a command line when you're in TCEXIT. %_cmdline is for use by key aliases that want to modify the contents of the command line.
If aliases are the only place it can be used reliable (and I'm not sure of that) it should be made clear in the halp file.

What about batch files? Can they reliably use _CMDLINE? It would appear not to be so.
Code:
g:\tc19> type tcexit.btm
echo %_cmdline
pause

g:\tc19> tcexit.btm
tce
Press any key when ready...
 
Then, with this TCEXIT
Code:
echo %_cmdline
pause

1. Why does is @exit command, when given on the command line, ALWAYS echoed by TCEXIT, while a simple "exit" is never echoed?
2. Why does "echo foo & exit", (typed, not history-recalled), cause the PAUSE not to be executed? The history-recalled version does it too if any changes were made to the recalled line ... adding a trailing space, for example, or simply moving the cursor in the recalled line without making a change.

You're doing a bad, bad, bad thing with %_cmdline. I would expect unpleasant things to happen with your usage, and I don't think it's worth spending the time to trace all the unexpected things you're triggering.

Don't ever use %_cmdline in a batch file. It cannot *possibly* return anything that would ever be of the slightest use.
 
Vincent, I'm not sure what you're trying to do. But it seems to me that if you want to hook EXIT, the smart way to do it would be through a plugin EXIT command. You can examine the command line, do anything you want with it -- or to it -- and then return the magic value 0xFEDCBA98 to let TCC do all its cleanup and exit. Or return anything else to prevent TCC from exiting.
 
I think the help does make it clear that it's intended to be used by key aliases. What did you think it would return in a batch file (where you don't have a command line)?
I don't think a parenthetical remark with "most useful in key aliases" makes it clear that that's about the only place it's useful.
_CMDLINE returns the current command line. (This is most useful in key aliases.)
And I never would have dreamed that batch files don't have a command line!
 
Vincent, I'm not sure what you're trying to do. But it seems to me that if you want to hook EXIT, the smart way to do it would be through a plugin EXIT command. You can examine the command line, do anything you want with it -- or to it -- and then return the magic value 0xFEDCBA98 to let TCC do all its cleanup and exit. Or return anything else to prevent TCC from exiting.
In another thread, someone asked if TCEXIT could tell why TCC was exiting. I immediately thought of _CMDLINE naively thinking batch files had command lines. That led me to an investigation that I'll gladly abandon.
 
In another thread, someone asked if TCEXIT could tell why TCC was exiting. I immediately thought of _CMDLINE naively thinking batch files had command lines. That led me to an investigation that I'll gladly abandon.

Ah. I think that's what _EXIT is for.
 
What you want is %_EXIT, and perhaps %CMDLINE or %CMDLINE2. Definitely not %_cmdline!
Speaking of CMDLINE2, what can you do with it? Any mention of it in a BTM file throws TCC into some sort of infinite loop which you can't Ctrl-C out of.

Try a simple BTM like this.
Code:
v:\> type cl2.btm
if "%CMDLINE2" == "foo" echo foo

v:\> cl2.btm
(it goes forever)

After reading the help, I would have expected (above) "CMDLINE2" to be "cl2.btm" (the original
unexpanded command line before doing any alias expansion, variable expansion, compound command processing, etc.).
 
Speaking of CMDLINE2, what can you do with it? Any mention of it in a BTM file throws TCC into some sort of infinite loop which you can't Ctrl-C out of.

No, but you certainly shouldn't be doing something like an IF expansion or ECHO with it. Consider what you're doing:

Everything goes fine until IF is expanding the line:

if "%CMDLINE2" == "foo" echo foo

which is first translated to:

if "if "%CMDLINE2" == "foo" echo foo" == "foo" echo foo

Ah, TCC says, there's a nested variable here. Let me expand it to:

if "if "if "%CMDLINE2" == "foo" echo foo" == "foo" echo foo" == "foo" echo foo

And so on, ad infinitum.

Either turn off nested variable expansion, or don't use CMDLINE2 where it's going to be recursively parsed. It's not a good idea to embed a %CMDLINE2 variable inside a %CMDLINE2 variable.
 
Can you use it at all without turning off nested variable expansion? Have you got an example?
 

Similar threads

Replies
1
Views
2K
Back
Top