Welcome!

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

SignUp Now!

A new CMD incompatibility

samintz

Scott Mintz
May
1,582
27
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
 
> 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.

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
 
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:


> ---Quote---
> > 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.
> ---End Quote---
> 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
>
>
>
>
 
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
 

Similar threads

Replies
0
Views
1K
Back
Top