Labels in batch files: TCC vs CMD.exe

Feb 27, 2018
11
0
The following batch file is runned differently by TCC and CMD:

@echo off
if not exist readme.txt (
:echo This is a comment
echo readme.txt does not exist
)


TCC silently ignores the "echo readme.txt does not exist" line (displays nothing) and CMD.exe echoes "readme.txt does not exist" as expected. This is not good for me because now I need to fix all my batch files. The TCC is declared to be fully compatible with CMD and I expected it to run existing batch files just as CMD does. Is it a bug or not? The TCC documentation says that :: can be used to comment out the line but then it must not be declared as fully compatible with CMD.
 
Feb 27, 2018
11
0
I've been using it (from 4DOS to 4OS2 to 4NT to TCC) for decades and have never seen this claimed. Where did you see this?

https://jpsoft.com/products/tcc-cmd-prompt.html
1519715794017.png
 
Dec 7, 2009
238
2
Left Coast, USA
If you want it to be a real comment, consider making it look like this:

:: echo This is a comment

When I made it that way and then ran your .cmd file under TCC v.20, the "readme.txt does not exist" line was displayed. Otherwise, it wasn't displayed.

I wouldn't trust cmd.exe always to respond correctly to the placement of a label within a command grouping like that in the first place (meaning a group of commands delimited by opening and closing parens). Years ago a team at work was having terrible problems with some of its .cmd files. The problem turned out to be lines beginning ":" or "::" within command groups. It was an obscure sort of problem that did not appear all the time, but when it did the batch files failed. Whether it could be considered a bug in cmd.exe, I don't know.

The fix was either to remove such comments entirely from those parts of the .cmd files, or use "REM" instead of "::" or ":" to start a comment line.

I've also used this command processor since the 4DOS days and have never seen a claim of complete TCC or 4DOS/4NT compatibility with cmd.exe, either.

Long time ago, before Windows was even available, I worked for some months as a contractor at Microsoft. It was a DOS-only world and the command processor was command.com. One day I found what looked like an odd bug in it. A co-worker who knew one of the developers for command.com took me to the guy's office. I was advised to be exceedingly polite. I tried to be, as I explained the problem. He listened for a moment and then with no expression on his face, grunted "Sounds like a bug." That was the end of the conversation. The bug was never fixed that I know of. That's MS's command processor for you. It just is what it is.
 
Sep 24, 2013
42
1
You inserted the word "fully". It's an important distinction.

Simply by virtue of "adding thousands of new features" there's no way it could ever be "fully" compatible.

That being said, Rex certainly strives for compatibility where it doesn't get in the way of TCC features or require disproportionate effort. I expect he'll comment.
 
Feb 27, 2018
11
0
You inserted the word "fully". It's an important distinction.

Simply by virtue of "adding thousands of new features" there's no way it could ever be "fully" compatible.

That being said, Rex certainly strives for compatibility where it doesn't get in the way of TCC features or require disproportionate effort. I expect he'll comment.
I just expected the TCC to run existing batch files just as CMD does. I thought that the phrase about compatibility at https://jpsoft.com/products/tcc-cmd-prompt.html was exactly about this.

Anyway, TCC may not interpret the line starting with : as CMD does but it does not explain why it silently ignores the next one.
 

rconn

Administrator
Staff member
May 14, 2008
12,363
150
The following batch file is runned differently by TCC and CMD:

@echo off
if not exist readme.txt (
:echo This is a comment
echo readme.txt does not exist
)


TCC silently ignores the "echo readme.txt does not exist" line (displays nothing) and CMD.exe echoes "readme.txt does not exist" as expected. This is not good for me because now I need to fix all my batch files. The TCC is declared to be fully compatible with CMD and I expected it to run existing batch files just as CMD does. Is it a bug or not? The TCC documentation says that :: can be used to comment out the line but then it must not be declared as fully compatible with CMD.

This is a CMD bug (or at best inconsistent undocumented behavior). A label line ignores things like command separators & conditional operators, and your batch file command group is converted to:

Code:
if not exist readme.txt ( :echo This is a comment & echo readme.txt does not exist )

Changing this existing behavior in TCC would break existing batch files that use one of those characters in their labels.
 
Sep 24, 2013
42
1
CMD has many undocumented behaviors and bugs that have been around for so long that people have come to rely on them. Rex tries to accommodate those where practical, but it will never be 100%.
 

rconn

Administrator
Staff member
May 14, 2008
12,363
150
The "Duplicate CMD.exe bugs" option is ON. I expected the TCC to work like CMD. At least for already existing batch files.

There are a lot of bugs in CMD that aren't duplicated in TCC, even with the "Duplicate CMD.EXE bugs" option.

To qualify for emulation in TCC, a CMD bug has to meet the following criteria:

1. It is a known (even if undocumented) issue
2. It is at least somewhat commonly used (either deliberately exploiting the CMD bug or in ignorance)
3. Does something useful
4. It won't break existing batch files that rely on the correct & documented behavior
5. It won't do something unexpected and bad to the system

Your bug is:

1. Previously unknown to everyone but you
2. Apparently unused by anyone but you
3. Does something marginally useful that could & should be done using the documented syntax
4. Would break existing batch files
5. Won't harm anything

So you only have #5 going for you at this point.

You're welcome to post a request to duplicate this bug on the Suggestions forum. But at this time I am reluctant to break existing functionality by issuing a patch for the current version.
 
Similar threads
Thread starter Title Forum Replies Date
fpefpe How to? shortcuts and batch files Support 4
vefatica `Back quotes` - command line vs. batch file Support 5
fpefpe How to? batch file size Support 2
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
P Kill all other instances of tcc from a btm batch file Support 2
fpefpe batch file ending early Support 18
R Batch Debugger Command Expansion Window Support 3
K robocopy cancelling batch file processing Support 28
A Unable to pass batch file arguments unaltered Support 18
K Batch debugger not stepping correctly Support 4
S incorrect message at start Cancel batch job 4START.bat ? (Y/N/A) : Support 1
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
P exit /b in batch files Support 7
vefatica Batch parameters broken? Support 2
cxxl Set encoding for batch file Support 4
dcantor How to? Batch file to be executed by TCSTART Support 4
J New lexer for TCC batch files. Support 0
T Fixed Problem with use of Batch parameters in the IDE Support 1
T Fixed IDE locks up if edit window for running batch is closed Support 6
T How to? Show the values of batch variables on the TCC screen Support 21
D Alias in batch file Support 3
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
vefatica Exit code of a batch file? Support 4
J cd command altered in batch file Support 3
MickeyF running a program from cmdline versus in batch file Support 1
B Batch file won't run if there is already an instance of TC 17 running Support 9
nickles Fixed Executing long command lines in a batch generates file name errors Support 16
T batch execution Support 9
rjperrella start /tabna leaves blank windows when running batch scripts Support 10
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
J Files Disappearing During Batch Execution Support 4
nickles Fixed In batch files, %0 now evaluates to the absolute path Support 9
D Installation batch files Support 5
Jay Sage WAD Possible Bug in Batch Parameters Support 7
C How to? run a batch file in administrator mode while debugging in take command software Support 1
R Unexpected 'Cancel Batch Job' prompts Support 13
cgunhouse Fixed bdebugger with not exist batch file causes a crash Support 2
Mezlo menu batch file questions Support 25
D Run all .CMD batch files with CMD.EXE Support 16
T Lua sharing data with batch files Support 2
F Minimising the command window running from a batch file Support 19
C How to? ctrl-c does not prompt "Terminate batch job" Support 2
S How to? Batch file problem Support 67
CWBillow Setting and changing Vars in batch files Support 26
S How to? Incorporate tables from HELP into batch file Support 15
vefatica Fixed DO, OSD, and cancel batch prompt Support 3

Similar threads