Welcome!

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

SignUp Now!

Bug in variable expansion

Aug
124
0
[Lates TCC (v67)]

[Cmd.exe]
> dir "%ProgramFiles(x86)%"
[...]
Directory of C:\Program Files (x86)

31-May-11 00:12 <DIR> .
[...]
1 File(s) 174 bytes
26 Dir(s) 112,201,871,360 bytes free

[TCC]
dir "%ProgramFiles(x86)"
TCC: (Sys) The system cannot find the file specified.
"C:\Program Files(x86)"
0 bytes in 0 files and 0 dirs
112,201,871,360 bytes free

Note that TCC has expanded %ProgramFiles(x86) to "C:\Program Files(x86)" (instead of "C:\Program Files (x86)" (with space between Files and (x86)".

But:
> set ProgramFiles(x86)
C:\Program Files (x86) (which is correct)
 
Note that TCC has expanded %ProgramFiles(x86) to "C:\Program Files(x86)" (instead of "C:\Program Files (x86)" (with space between Files and (x86)".

Not a bug. The ( and ) are not valid variable name characters, so the parser is expanding "%ProgramFiles" and then appending "(x86)" to the result.

If you want to use unusual characters in the filename, you can force the parser to recognize them with the [] syntax:

echo %[ProgramFiles(x86)]

Or you can use the CMDVariables=Yes option in your TCMD.INI, which will force all variable expansion to use the CMD syntax (which requires a leading and trailing %).
<DIR>
</DIR>
 
So Microsoft is not following its own rules by including characters which are not valid as variable names? Or does it just not follow TCC's rules?

Anyway, the %[] is very good advice.

Thanks, Thorsten
 
So Microsoft is not following its own rules by including characters which are not valid as variable names?
Who knows, since I don't suppose it is documented anywhere and even Windows XP lets me create variables with brackets in the name. Under CMD it will never be an issue (because you have to close the variable name with a second percent sign) but 4DOS et al have always worked differently. The thing that really bugs me is why include the brackets at all, since ProgramFilesx86 would be just as sensible a name.
 
Back
Top
[FOX] Ultimate Translator
Translate