A collection of incompatibilities with CMD.EXE

Jun 13, 2008
12
0
Here is a couple of TCC's incompatibilities with CMD.EXE I've discovered. To check any of them, create file Test.cmd, paste an example there, save Test.cmd and run it first under TCC.EXE then under CMD.EXE and compare outputs.

1. set aaa=c:\windows\
for %%a in (%aaa%nul) do echo %%~dpa

2. setlocal enabledelayedexpansion
set Prm1=Test
for /l %%a in (1,1,1) do (
echo !Prm%%a!
)

3. [supposing there is an empty folder "C:\Empty\1 1" with short name C:\EMPTY\110994~1]
if exist 110994~1\nul echo

4. setlocal enabledelayedexpansion
call :a c:\windows\
call :a c:\windows
exit /b
:a
set DirName=!%1!
echo %DirName:~-1%

5. verify other 2>nul
call :a && echo b
exit
:a

6. verify other 2>nul && (
echo 1
echo 2
)

7. [run Test.cmd with parameter ""]
set testString_=%1
echo %testString_%

8. setlocal enabledelayedexpansion
set s=123
for /L %%c in (0,1,255) do (
set si=!s:~%%c,1!
if defined si set charCount=%%c
)
echo %charCount%

9. set aaa="bbb"
if [^%aaa:~,1%] == [^"] echo ###

10. setlocal disableextensions
set a
 
Jun 13, 2008
12
0
Can I please hope that these incompatibilities will be gone with next releases?
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
Raistlin wrote:

> Here is a couple of TCC's incompatibilities with CMD.EXE I've discovered. To check any of them, create file Test.cmd, paste an example there, save Test.cmd and run it first under TCC.EXE then under CMD.EXE and compare outputs.

You didn't say which version of TCC you're using, or which version of
CMD (they vary slightly in different Windows versions).


> 1. set aaa=c:\windows\
> for %%a in (%aaa%nul) do echo %%~dpa

This appears to be at best an undocumented and useless CMD peculiarity,
though it's more likely just a bug. (CMD is turning "c:\windows\nul"
into "\\.".)


> 2. setlocal enabledelayedexpansion
> set Prm1=Test
> for /l %%a in (1,1,1) do (
> echo !Prm%%a!
> )

TCC doesn't supported embedded variables in delayed expansion variables,
as this would require crippling the parser to not allow dynamic variable
expansion (thus duplicating the CMD behavior). This would also break
most existing batch files, so I doubt it would be too popular with the
rest of the users.


> 3. [supposing there is an empty folder "C:\Empty\1 1" with short name C:\EMPTY\110994~1]
> if exist 110994~1\nul echo

CMD and TCC behave identically, provided you turn on SFN file searching
(OPTION/Startup) in TCC. But I wouldn't recommend it, as it can result
in some very unpleasant results with commands like DEL.


> 4. setlocal enabledelayedexpansion
> call :a c:\windows\
> call :a c:\windows
> exit /b
> :a
> set DirName=!%1!
> echo %DirName:~-1%

Duplicate of #2.


> 5. verify other 2>nul
> call :a && echo b
> exit
> :a

CMD undocumented behavior/bug - it's interpreting the conditional
command "&&" as a batch argument.


> 6. verify other 2>nul && (
> echo 1
> echo 2
> )

The TCC parser is stricter than CMD, and only allows command groups for
internal commands where it makes sense to have a command group, like
FOR, IF, IFF, etc. There's no reason to use one in VERIFY (which is a
no-op command anyway in CMD).


> 7. [run Test.cmd with parameter ""]
> set testString_=%1
> echo %testString_%

CMD and TCC behave identically here.


> 8. setlocal enabledelayedexpansion
> set s=123
> for /L %%c in (0,1,255) do (
> set si=!s:~%%c,1!
> if defined si set charCount=%%c
> )
> echo %charCount%

Another duplicate of #2.


> 9. set aaa="bbb"
> if [^%aaa:~,1%] == [^"] echo ###

CMD bug - it's ignoring the escape char in the first argument.


> 10. setlocal disableextensions
> set a

WAD - see the docs for SET. SET behaved this way before this was added
to CMD, so it didn't make sense to remove a feature in order to match an
"occasional" feature in CMD.

Rex Conn
JP Software
 
Jun 13, 2008
12
0
Another incompatibility. Executing following batch file
Code:
@echo off
call :aaa || echo Error
exit /b

:aaa
exit /b 1
will give different results under TCC and CMD (see in my signature for their versions).
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
> Another incompatibility. Executing following batch file
> Code:
> ---------
> @echo off
> call :aaa || echo Error
> exit /b
>
> :aaa
> exit /b 1
> ---------
> will give different results under TCC and CMD (see in my signature for
> their versions).

CMD's behavior is undocumented and (apparently) useless -- why do you need
it?

Rex Conn
JP Software
 
Jun 13, 2008
12
0
Why useless? It's a comfortable way to check if a subroutine returned an error, instead of additional "if errorlevel 1..."

Take Command Console (TCC) - A command processor compatible with CMD.EXE
It is not, actually. I agree that a lot of incompatibilities I've described above is a result of CMD.EXE creators' mistakes, but they are really used as features, because CMD.EXE is poor of "real" features. So TCC IMHO should be able to emulate these bugs if it is called "compatible with CMD.EXE". Maybe via "CmdBugs = On" (while default is Off) in INI file, doesn't matter. Now I just need to add at the beginning of my scripts:
Code:
for %%A in ("%ComSpec%") do if not %%~nxA == cmd.exe (
  cmd.exe /c %0 %*
  exit /b %errorlevel%
)
Why can't I just use TCC directives instead of CMD.EXE's ones? Because these scripts are also used in admin tasks. They should work on any computer.
I believe I'm not alone in that.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
> ---Quote---
> *Take Command **Console* (*TCC*) - A command processor compatible with
> CMD.EXE
> ---End Quote---
> It is not, actually. I agree that a lot of incompatibilities I've
> described above is a result of CMD.EXE creators' mistakes, but they are
> really used as features, because CMD.EXE is poor of "real" features. So
> TCC IMHO should be able to emulate these bugs if it is called
> "compatible with CMD.EXE". Maybe via "CmdBugs = On" (while default is
> Off) in INI file, doesn't matter

It is impossible to be 100% compatible with CMD, because:

1) CMD isn't compatible with CMD (different versions behave differently)

2) In many cases (as in your latest example) CMD has belatedly added a
feature that 4DOS / 4NT / TCC has had for years. That means I either have
to break everybody's existing aliases & batch files, or accept that the CMD
behavior is going to be different.

3) And the only way to be 100% compatible is to eliminate all the extra TCC
features, which would result in a product that not many people would care to
use ...

Rex Conn
JP Software
 
Similar threads
Thread starter Title Forum Replies Date
vefatica Big collection of MSI files Support 3
T WAD CMD incompatibility Support 14
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
L FTYPE in TCC, less quirky than in cmd.exe Support 3
Peter Murschall Single-line Do-CMD is a bit uncooperative. Support 6
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
T Date format date different from cmd Support 7
D Differences between TCC and CMD with COPY /b Support 4
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
E TCC/CMD difference Support 5
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
D How to? Pass OpenHere Folder to CMD? Support 6
R Difference between TCC and CMD: variable names with hyphens Support 4
M WAD "Pictures" directory is empty in TCC but not in CMD or Explorer Support 4
rps Cmd history recall Support 4
rps Documentation TITLE cmd docs Support 0
Joe Caverly PUSHD with UNC path in CMD.EXE Support 2
W Starting program for word to pdf conversion (difference cmd and tcc) Support 13
Joe Caverly Using this CMD technique from TCC Support 17
W If command - different with CMD Support 6
I how to make TCC default/replace cmd.exe? Support 9
R FOR usage error from TCC but not from CMD Support 16
I findstr works in cmd but not in tcc Support 5
D Pasting Unicode data has different behavior on TCC and CMD Support 2
M Command line parsing differences between cmd.exe and TCC Support 6
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
Joe Caverly tcommand(cmd) Support 13
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
Joe Caverly "Functions" in cmd.exe batch files Support 6
Joe Caverly Works in debugger, not from cmd line Support 1
K CMD, TCC, VisualStudio 2017, VcVars* differences Support 1
D Does TCC improve CMD's implementation of ECHO? Support 6
P Labels in batch files: TCC vs CMD.exe Support 9
Patulus Yet another thread on CMD compatibility Support 16
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
Joe Caverly CMD.EXE and filename(1).ext Support 3
H DOS CMD Sort+Add Sequence+Remove Sequence number Support 12
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
C Nested IF syntax — TCC behaving differently to CMD Support 12
T CMD incompatibility Support 14
V Network share slowness vs CMD? Support 19
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
R How to? Display text same as in CMD Support 14
E How to? use Executable Extensions: .bat and .cmd Support 8
D Tab completion differences with cmd.exe Support 3
deleyd Fixed Behavior different than CMD Support 1
vefatica START, CMD vs. TCC Support 0
R Difference in behavior of RMDIR vs. CMD.EXE? Support 5
jogi Problem with FOR statement in TCC but not M$ CMD Support 1

Similar threads