Welcome!

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

SignUp Now!

endlocal incompatibiliy with cmd.exe

Mar
3
0
Hi,

consider this batch file:

@rem endlocal test
@setlocal
@set _XBLA_=Hello
@for %%A in (%_XBLA_%) do @endlocal & @echo %%~A

In cmd.exe it displays "Hello", in tcc it displays "ECHO is off".

TCC 29.00.17 x64 Windows 10 [Version 10.0.19045.3208]

This seems to prevent the python "conda" environment to work with tcc.

regards,
chris
 
I believe this is caused by a difference between CMD's FOR and TCC's FOR. With CMD's FOR, when you say

for ... do a & b you get both a & b every time through the loop (i.e., "& b" is part of the loop).

In TCC, for ... do a & b is the same as

Code:
for ... do a
b

Apparently this difference is not corrected by OPTION\Startup\DuplicateCMDBugs.

This works in both shells.

Code:
@echo off
rem endlocal test
setlocal
set _XBLA_=Hello
for %%A in (%_XBLA_%) do (endlocal & echo %%~A)
 
I'm confused. Why would you want to do an ENDLOCAL inside a loop?
Yeah, it doesn't make much sense. But it led me to experiments that make me wonder exactly when ENDLOCAL is executed and when you see its consequences. And there is a TCC/CMD difference.

Code:
v:\> type eltest.bat
@echo off
setlocal & set zz= & set zz=foo & endlocal & echo %zz%

v:\> set zz
TCC: Not in environment "zz*"

v:\> d:\tc30\tcc.exe /c eltest.bat
foo

v:\> cmd /c eltest.bat
ECHO is off.
 
I have learned the hard way not to try and run long, complicated batch files downloaded from the internet using TCC instead of CMD. If they were written to run under CMD.EXE, then just save yourself the headaches and go with it. I have used TCC since the days of 4DOS, and appreciate everything that it brings, but when you need CMD, go with it.
 
The problem is that this batch file opens a new command-line environment with conda settings and I want to have TCC there inside. But maybe I can just start it on top, or modify this batch file.
 
The problem is that this batch file opens a new command-line environment with conda settings and I want to have TCC there inside. But maybe I can just start it on top, or modify this batch file.
Rewrite it as a .BTM? TCC looks for .BTM files before .CMD; cmd‍.exe ignores them.
 

Similar threads

Replies
0
Views
1K
Back
Top