Welcome!

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

SignUp Now!

Labels in batch files: TCC vs CMD.exe

Feb
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.
 
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
 
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.
 
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.
 
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.
 
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.
 
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%.
 
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.
 
I just got caught by this weird bug or strange behavior or whatever you might call it. Problem under CMD, not TCC.

The problem is on line 9, the comment beginning with "::". Under TCC, everything is kosher. Under CMD, I get ") was unexpected at this time." If I change line 9 to use "REM" instead of "::", everything works as expected.

2024-01-20_15-28-10.png
 
Interesting! If you put an empty line before the closing ')' you get a different error. If you put an actual command there (with or without a subsequent empty line) the problem goes away. Do you think TCC should emulate both of these?

Code:
v:\> type rem2.bat
@echo off
:: comment
if 01 == 1 (
    echo foo
    :: remark
)

v:\> rem2.bat
) was unexpected at this time.

Code:
v:\> type rem2.bat
@echo off
:: comment
if 01 == 1 (
    echo foo
    :: remark

)

v:\> rem2.bat
The syntax of the command is incorrect.

Code:
v:\> type rem2.bat
@echo off
:: comment
if 01 == 1 (
    echo foo
    :: remark
    echo bar
)

v:\> rem2.bat

v:\>
 
I think the explanation given in post #7 (above), mostly explains what is going on. Mostly, but not completely.

What I don't like is how this will, at least in some cases, argue against using :: as a remark separator. I personally prefer the ::, I think it looks a lot better. I'm quite used to using "#" , and I really wish Bill Gates or whomever had just gone with using a "#". If I'm recalling correctly, the "REM" was actually inherited from Basic.
 
I just got caught by this weird bug or strange behavior or whatever you might call it. Problem under CMD, not TCC.

The problem is on line 9, the comment beginning with "::". Under TCC, everything is kosher. Under CMD, I get ") was unexpected at this time." If I change line 9 to use "REM" instead of "::", everything works as expected.

View attachment 4224

You're trying to use a TCC feature in CMD (well, actually two TCC features). If you want to run this in CMD, you'll have to use REM instead of ::.
 
This entire thread highlights why I have stubbornly stuck with 'rem' over all the other options in batch files for years. It's the only thing that has never given me trouble, ugly and undesirable as it may be.
 

Similar threads

Back
Top