1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A collection of incompatibilities with CMD.EXE

Discussion in 'Support' started by Raistlin, May 26, 2009.

  1. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    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
     
  2. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Can I please hope that these incompatibilities will be gone with next releases?
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    Raistlin wrote:

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


    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 "\\.".)


    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.


    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.


    Duplicate of #2.


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


    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).


    CMD and TCC behave identically here.


    Another duplicate of #2.


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


    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
     
  4. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    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).
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    CMD's behavior is undocumented and (apparently) useless -- why do you need
    it?

    Rex Conn
    JP Software
     
  6. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Why useless? It's a comfortable way to check if a subroutine returned an error, instead of additional "if errorlevel 1..."

    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.
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    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
     

Share This Page