Welcome!

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

SignUp Now!

How to? SOLVED: does UNKNOWN_CMD have access to the line number? [answer: yes, via %_BATCHLINE]

Jul
532
10
1) I have an unknown_cmd.bat which my unknown_cmd alias points to. (My practice is usually to have my aliases call bat files and handle the logic in there.)

2)I have a status-bar.bat

3) I got this error:
1737920461793.webp


4) Nowhere in that BAT file is there a line that says ’unlock’. The word appears in mid line, but ... the command isn’t being issued. And I’m using loadbtm on so even if the BAT file was modified, this shoudln’t happen.

Source of BAT: clairecjs_bat/BAT-and-UTIL-files-1/status-bar.bat at main · ClaireCJS/clairecjs_bat


5) i’d like to figure this out without turning echo on because it would drown out the output i’m actually trying to look at

6) Therefore, it would be nice if my unknown-command.bat could tell me more than "in status-bar.bat", but tell me WHICH LINE THIS IS HAPPENING ON.

I feel like I saw this in the docs somewhere, but maybe it’s a v34 feature (i’m on 33)
 
There is _BATCHLINE. But if your unknown-command handler is itself a batch file, I think using _BATCHLINE would require a bit of sneakiness. Maybe have your UNKNOWN_CMD alias save _BATCHLINE to an environment variable before calling the second batch file.
 
Just my experience with unknown_cmd alias.

Once you have entered your unknown_cmd.bat file,
make sure to issue unalias unknown_cmd before doing anything else.

At the end of your unknown_cmd.bat file,
make sure to issue alias unknown_cmd=%_batchname.

I was looking for your unknown_cmd.bat on your github site,
but I received the message;

Sorry, we had to truncate this directory to 1,000 files. 259 entries were omitted from the list. Latest commit info may be omitted.

...as you have over 1,000 files in a single folder.

Joe
 
Not sure if you are familiar with the DEBUGSTRING command.

I find it quite useful.

I use DebugView as the DEBUGSTRING viewer.

Joe
 
Just my experience with unknown_cmd alias.

Once you have entered your unknown_cmd.bat file,
make sure to issue unalias unknown_cmd before doing anything else.

At the end of your unknown_cmd.bat file,
make sure to issue alias unknown_cmd=%_batchname.

Well, I don’t want to do that because if there’s an unknown command in my unknown_cmd.bat, i want it to be reacted to the same way. It includes a pause so all execution is stopped until i come back and deal with it, so it’s not like i’m going to end up in a maximum-bat-nesting-depth situation.

I was looking for your unknown_cmd.bat on your github site,
but I received the message;

Sorry, we had to truncate this directory to 1,000 files. 259 entries were omitted from the list. Latest commit info may be omitted.

...as you have over 1,000 files in a single folder.

Oh i totally mis-read what you said and had to edit my response.

Yea, that happens.

I have a 2ⁿᵈ folder where the later ½ of the alphabet is re-copied to get around the 1,000 limit.

It’s just "BAT-2" instead of "BAT-1".

I was super upset when I found out about the 1,000 file limit. I suppose I could categorize them in subfolders maybe.
 
There is _BATCHLINE. But if your unknown-command handler is itself a batch file, I think using _BATCHLINE would require a bit of sneakiness. Maybe have your UNKNOWN_CMD alias save _BATCHLINE to an environment variable before calling the second batch file.
I think could just pass it as a parameter from the alias to the BAT the alias calls. I’m gonna try :)

Update: Yup, that worked! Thanks!!!!!
 
Last edited:
So, I updated my alias to:

Code:
UNKNOWN_CMD=call unknown_cmd.bat BATCHLINE %_BATCHLINE %1$

And added code in unkonwn_cmd.bat to detect it:

Code:
*iff "%1" == "BATCHLINE" then
        shift
        set BATCHLINE=%1
        shift  
*else
        unset /q BATCHLINE
*endiff

And then later added the line number when unkonwn commands happen in a BAT file, but the line won’t happen if it’s an unknown command at the command line:

Code:
*if defined BATCHLINE *echoerr  %ANSI_COLOR_ERROR% Line number: %italics%%ANSI_BRIGHT_YELLOW%%BATCHLINE%%ANSI_COLOR_ERROR%%italics_off%

Much nicer! I’ll be able to solve a lot of my problems much easier now! It’s been great catching up!!

1737929790737.webp
 
Back
Top