A new CMD incompatibility

samintz

Scott Mintz
May 20, 2008
1,495
16
Solon, OH, USA
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
 

rconn

Administrator
Staff member
May 14, 2008
12,340
149
> 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
 

samintz

Scott Mintz
May 20, 2008
1,495
16
Solon, OH, USA
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
>
>
>
>
 
Apr 1, 2010
43
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
 
Similar threads
Thread starter Title Forum Replies Date
T CMD incompatibility Support 14
J Happy CMD/TCC incompatibility Support 0
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
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
C Documentation .CMD .BAT .BTM Support 15

Similar threads