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

A new CMD incompatibility

Discussion in 'Support' started by samintz, Apr 29, 2010.

  1. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    I downloaded a trial version of Raima's RDMe embedded database. It's
    software designed for embedding a database within embedded devices. They
    have a setup BAT file that sets up your build environment depending on
    whether you're building for 32bit, 64bit, ia64, or WinCE.

    The problem piece of code is (of course) in the FOR statement. You'll
    notice the command is enclosed in both single quotes and double quotes.
    Because of the double quotes, TCC attempts to execute "CL 2>&1" as a
    command and fails. If I remove the double quotes, then the STDERR output
    doesn't make it into the token variable.

    Code:
       :: Set the compiler information
     
    ::---------------------------------------------------------------------------
       set NEXT   set MSVC7   set MSVC8   set MSVC9
       REM Parse the cl command - redirect stderr to stdout, that's where the
       REM version number is. There is no '-v' option.
    
       FOR /F "tokens=*" %%G IN ('"cl 2>&1"') DO  call :parseit %%G
       goto :END-COMPILER
    
       REM parseit gets the whole line, loop through one word at a time. 
       REM Look for 'version'. When we find 'version', the next word is the 
       REM version number
    :parseit
       if {%1}=={'cl'} goto :ERROR_COMPILER
       if {%1}=={} goto :END
       REM echo %1
    
       if defined NEXT call :parseversion %1
       if defined NEXT goto :END
       if /I %1==version set NEXT=1
       shift /1
       goto :parseit
       goto :eof
    
       REM The version number is like 14.00.22.33.44.  The delims options 
    isn't
       REM working so I'm just reading the first two characters
    
    :parseversion
       REM FOR /F "delims=. tokens=1" %%H IN ('echo %%1') do call :setvers %%H
       set string=%1
    
       REM Skip lines that aren't version numbers
       IF NOT "%string:~0,1%"=="1" goto :eof
       set COMPILER_VERSION=%string%
       IF "%string:~0,2%"=="13" set MSVC7=1
       IF "%string:~0,2%"=="14" set MSVC8=1
       IF "%string:~0,2%"=="15" set MSVC9=1
       goto :eof
    
    :END-COMPILER
    
    -Scott
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    This is an ooooolllllddd problem. I thought that modern batch file writers
    weren't quite as dense and had fixed their files!

    CMD doesn't recognize "CL 2>&1" as a command either -- what it does is first
    try to execute the quoted string, and when that fails it removes the quotes
    and tries executing the first token. 4NT used to do this, but I eventually
    removed it because users were having problems when they misspelled a quoted
    command, and then saw 4NT execute something quite unexpected.

    Rex Conn
    JP Software
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    What about the second issue? If I modify the batch file and remove the
    double quotes, the STDERR redirection doesn't seem to be happening.
    -Scott

    rconn <> wrote on 04/29/2010 07:49:03 PM:


    quotes.

    writers

    first

    quotes

    eventually

    quoted

     
  4. roytam1

    Joined:
    Apr 1, 2010
    Messages:
    43
    Likes Received:
    0
    It fails even have "usebackq" in FOR (code from RosBE):
    Code:
    for /f "usebackq tokens=3" %%i in (`"gcc -v 2>&1 | find "gcc version""`) do set _ROSBE_GCCVERSION=%%i
    for /f "usebackq tokens=2" %%i in (`"gcc -v 2>&1 | find "Target""`) do set _ROSBE_GCCTARGET=%%i
    
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    That's not relevant; the problem is with the double quotes.

    Rex Conn
    JP Software
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    Not reproducible here.

    Rex Conn
    JP Software
     

Share This Page