Welcome!

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

SignUp Now!

Nested setlocal gives problems with aliases resolving in DO /P

Dec
20
2
There is a problem when we used nested setlocal.

We have two batch files
DO_P.btm

Code:
setlocal
echo OsBuild=%_OSbuildEx
which cl_grep
cl_grep
call dummy.btm

set _key=HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault

do c in /P `regdir /dfv %_key | CL_grep -i ".current[\]"`
  echo %c
enddo
endlocal

dummy.btm
Code:
setlocal & echo Dummy Text & endlocal
quit

Call DO_P gives:
Code:
OsBuild=22000.376
CL_grep is an alias : "CLPath:\grep.exe"
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
This Dummy Text
TCC: R:\do_P.btm [10]  Unknown command "CLPath:\grep.exe" -i ".current[\]"


If we remove the dummy call in DO_P it works
or we remove the setlocal from dummy.btm
or we redefine the alias CL_grep to %@ALIAS[CLPATH:]\grep.exe

How do we solve this issue?
 
Which version of TCC are you using?

It's OK here with TCC 28.02.18 (and back to TCC v24), imitating your example the best I can. The grep error message is coming from line 4 where CL_grep is called with no arguments. Otherwise, I think this (below) is what's expected. From the TCC error message I'd guess is that the CLPath: alias does not exist or is not referenced correctly. If your TCC is not up to date, it might be a bug that has been fixed.

Code:
v:\> alias CLPath:
d:\gnu

v:\> alias CL_grep
CLPath:\grep

v:\> type niros1.btm
setlocal
echo OsBuild=%_OSbuildEx
which cl_grep
cl_grep
call dummy.btm

set _key=HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault

do c in /P `regdir /dfv %_key | cl_grep -i ".current[\\]"`
  echo %c
enddo
endlocal

v:\> type dummy.btm
setlocal & echo Dummy Text & endlocal
quit

v:\> niros1.btm
OsBuild=19044.1415
CL_grep is an alias : CLPath:\grep
Usage: d:\gnu\grep [OPTION]... PATTERN [FILE]...
Try `d:\gnu\grep --help' for more information.
Dummy Text
HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault\.Current\ : REG_SZ :
 
P.S., I tested this with LocalAliases=No (my default) and LocalAliases=Yes. It worked in both cases.
 
TCC Version 28.02.18 x64 and the aliases are global.

Just before the DO /P the command CL_grep is executed with no parameter so the command executes and the CLPATH: is resolved.
Maybe the global /local aliases makes the difference.
 
Try which CLPath: before and after call dummy.btm

Here global/local made no difference. But in the local test I had to manually create the aliases.
 
Before and after the call dummy the CLPATH: is ok.
In the next line DO /P ... TCC do not resolve the CLPATH: alias.
 
CL_grep is run in a new instance of TCC. With global aliases, that should be OK. Do you use a TCSTART.BTM? If so, does it do anything that might mess with the aliases?
 
TCSTART.BTM is used and there the aliases are loaded if not already defined.
Also the library file and functions are loaded at first start of a TCC session.
 
This is TCSTARTUP.BTM

IFF %_SHELL == 0 then :: ECHO SHELL=%_SHELL startpath=%_startpath Set _tcc_commonpath=%@left[-3,%@path[%_cmdspec]] iff not isAlias dir then REM ECHO Load aliases alias /r %_tcc_commonpath\tcc_common.als DIRHISTORY /R %_tcc_commonpath\DIRHISTORY.TXT set prompt=[$P]$_ if exist %_tcc_commonpath\function.lst function /GL /R %_tcc_commonpath\function.lst ENDIFF IFF isdir %_tcc_commonpath\Library THEN :: echo Load Library Files: for %file in ( %_tcc_commonpath\Library\*.*) (Library /R %file) :: Library /R * ELSE Echo TCC:%_4ver *** Library Subdirectory does not exist!. ECHO CWD=%_CWD ENDIFF unSet _tcc_commonpath ENDIFF if %COMPUTERNAME == M2800 .AND. %@ready[R:] == 1 R:
 
Here's a simple test. It will show you if you have the CL* aliases in a piped instance of TCC. You could also put that in your BTM right before the DO with the failing call to CL_grep.

Code:
echo. | alias CL*
 
Maybe the problem is solved.
The %_SHELL test in the STARTUP.BTM is removed.
Now its seems to work.
 
M2800.jpg

Options all global is that enough?

BTW now a error in the STARTUP 'No functions defined'
 
The /GL switch does this.
If we add the /GL switch by the ALIAS /R command 'No aliases defined' message also appears.
 
it seems that the ALIASEN are not global to a secondary shell?

call DO_P.btm OSBuild=17763.2366 TCC=28.02 Dummy SHELL=1 startpath=Z:\Packages\Tweaks Z:\Programs\Utility\TCC\TCSTART.btm Load aliases c=HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault\.Current\ : REG_SZ :
 
I don't understand what those messages mean or where they are coming from.
 
In nested 'setlocal''s the secondary shell does not get the global aliasses.

Workaround for now by changing TCSTARTUP.BTM
Removed the /GL switch from the function command for the no function message
Removed the %_SHELL == 0 test so the aliasses can be loaded (if necessary) in secondary shells.

vefatica

Thanks for the assistance and the quick responses.
 
Last edited:
In nested 'setlocal''s the secondary shell does not get the global aliasses.
They sure do here!

Code:
v:\> type nested.btm
echo 1 & alias CL*
setlocal
echo 2 & alias CL*
call dummy.btm
echo 3 &alias CL*
endlocal
echo 4 & alias CL*

v:\> type dummy.btm
echo 5 & alias CL*
setlocal
echo 6 & alias CL*
echo Dummy Text
endlocal
echo 7 & alias CL*
quit

v:\> nested.btm
1
CL_grep=CLPath:\grep
CLPath:=d:\gnu
2
CL_grep=CLPath:\grep
CLPath:=d:\gnu
5
CL_grep=CLPath:\grep
CLPath:=d:\gnu
6
CL_grep=CLPath:\grep
CLPath:=d:\gnu
Dummy Text
7
CL_grep=CLPath:\grep
CLPath:=d:\gnu
3
CL_grep=CLPath:\grep
CLPath:=d:\gnu
4
CL_grep=CLPath:\grep
CLPath:=d:\gnu

My TCSTART.BTM is quite simple.

Code:
IF "%_PIPE %_TRANSIENT" != "0 0" QUIT
SET TMP=z:\
SET TEMP=z:\
IF %_ELEVATED == 1 CALL d:\tc24\admin.btm
ECHO.

Do you have [Primary] and [Secondary] sections in TCMD.INI? [You shouldn't.]
 
No not a [primary] or [secondary] in TCMD.INI
Add your first line of STARTUP.BTM to my startup

Another test based on your nested.btm & dummy.btm
[R:\] type nested.btm echo 1 & alias CL_Grep setlocal set _key=HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault DO c in /P `regdir /dfv %_key | CL_grep -i ".default[\].*.current[\]"` (echo %c) echo 2 & alias CL_Grep call dummy.btm DO c in /P `regdir /dfv %_key | CL_grep -i ".default[\].*.current[\]"` (echo %c) echo 3 &alias CL_Grep endlocal echo 4 & alias CL_Grep [R:\] type dummy.btm echo 5 & alias CL_Grep setlocal echo 6 & alias CL_Grep echo Dummy Text endlocal echo 7 & alias CL_Grep quit [R:\] nested 1 "CLPath:\grep.exe" HKCU\AppEvents\Schemes\Apps\.Default\AppGPFault\.Current\ : REG_SZ : 2 "CLPath:\grep.exe" 5 "CLPath:\grep.exe" 6 "CLPath:\grep.exe" Dummy Text 7 "CLPath:\grep.exe" TCC: R:\nested.btm [7] Unknown command "CLPath:\grep.exe" -i ".default[\].*.current[\]" 3 "CLPath:\grep.exe" 4 "CLPath:\grep.exe"
 
I'm really curious about what's going on. Try adding this (use CL* to get both aliases).

Code:
call dummy.btm
echos 2.5 & alias CL*
DO c in /P `regdir /dfv %_key | CL_grep -i ".default[\].*.current[\]"` (echo %c)
 
CL* gives a lot output so truncated
2.5CLPath:=Z:\Programs\75 Utility\20-CMDLineTools CL_AWK="CLPath:\gawk.exe" CL_CPAU="CLPath:\CPAU.exe" CL_DellThermal_ShowCurrent=Echo DellSetThermalSettings Current Mode = %@EXECSTR[CL_DellTherma -b] CL_DellThermal_Optimized=CL_DellThermal Optimized CL_DellThermal_Quiet=CL_DellThermal Quiet CL_DellThermal_Cool=CL_DellThermal Cool CL_DellThermal_Ultra=CL_DellThermal UltraPerformance CL_DellThermal="CLPath:\DellGetSetThermalState.exe" CL_devcon="CLPath:\devcon64.exe" CL_dosdev="CLPath:\dosdev.exe" CL_dotnetver="CLPath:\dotnetversions.exe" CL_EPAL="CLPath:\EPAL.exe" CL_grep="CLPath:\grep.exe"


TCC: R:\nested.btm [8] Unknown command "CLPath:\grep.exe" -i ".default[\].*.current[\]"
 
CL_grep has a space in it! That'll never work. Try calling "CL_grep".
 
CL_grep has a space in it! That'll never work. Try calling "CL_grep".
OK, I see that it's quoted. But TCC is seeing the whole thing as the name of the EXE.

So now I have this.

Code:
v:\> alias cl*
CL_grep="CLPath:\grep"
CLPath:=v:\a b

And I removed the ""s from the regular expression (they weren't needed). Now I get

Code:
TCC: V:\nested.btm [7]  Unknown command "CLPath:\grep"

which is better but still not good.

I also see that it works without the call to DUMMY.BTM. And it works if DUMMY.BTM doesn't setlocal/endlocal.

Somehow, the CALL to a BTM with SETLOCAL/ENDLOCAL is messing up the alias expansion. That seems wrong. If I can't find a quick fix, I'll condense the problem into something small and start a new thread. Hopefully, Rex will chime in.

I guess we're back at the beginning of this thread. :confused:
 

Similar threads

Back
Top