Welcome!

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

SignUp Now!

Environment variable oddity

May
550
6
I am attempting to use the ProgramFiles(x86) variable in a batch file, but Take Command removes the space. See below -

Code:
C:\> ver

TCC  12.00.29 x64   Windows 7 [Version 6.1.7600]

C:\> set Prog
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

C:\> echo %ProgramFiles(x86)%
C:\Program Files(x86)

C:\>
 
CMD behaves correctly:

Code:
C:\> set Prog
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

C:\> echo %ProgramFiles(x86)%
C:\Program Files (x86)

C:\>
 
Both of your examples show exactly the same thing.

What's not working?

As an alternative to what you are attempting, you may consider using short
file names instead and avoid the whole space issue.

-Scott

Rod Savard <> wrote on 10/22/2010 06:10:47 PM:


> CMD behaves correctly:
>
>
> Code:
> ---------
> C:\> set Prog
> ProgramData=C:\ProgramData
> ProgramFiles=C:\Program Files
> ProgramFiles(x86)=C:\Program Files (x86)
> ProgramW6432=C:\Program Files
>
> C:\> echo %ProgramFiles(x86)%
> C:\Program Files (x86)
>
> C:\>
> ---------
>
>
>
 
No, they don't show the same thing. Look more closely at the echo output in Take Command verses CMD.

Take Command strips out a space, which makes it not work.

you may consider using short file names instead and avoid the whole space issue.
How so? The whole reason I want to use this environment variable is because we don't know the Program Files folder is necessarily on the C: drive. Plus I want it to work regardless of CMD or Take Command being used (so I don't want to use @SHFOLDER).

It SHOULD work -- there is something wrong with how Take Command is parsing this variable name. Perhaps the parens are confusing it.
 
I see the issue now. The TCC parser stops parsing when it sees the open
paren.

If you change the ProgramFiles(x86) variable to C:\Program Files (x586)
and re-run your test, you'll see the echo is the same:

C:\> echo %ProgramFiles(x86)%
C:\Program Files(x86)

TCC is evaluating %ProgramFiles and then appending the (x86) text to that
result.

You can either not use parens, or use the bracketed syntax:
echo %[ProgramFiles(x86)]

-Scott

Rod Savard <> wrote on 10/22/2010 06:08:24 PM:


> I am attempting to use the ProgramFiles(x86) variable in a batch
> file, but Take Command removes the space. See below -
>
>
> Code:
> ---------
> C:\> ver
>
> TCC 12.00.29 x64 Windows 7 [Version 6.1.7600]
>
> C:\> set Prog
> ProgramData=C:\ProgramData
> ProgramFiles=C:\Program Files
> ProgramFiles(x86)=C:\Program Files (x86)
> ProgramW6432=C:\Program Files
>
> C:\> echo %ProgramFiles(x86)%
> C:\Program Files(x86)
>
> C:\>
> ---------
>
>
>
 
On Fri, 22 Oct 2010 18:08:26 -0400, Rod Savard <> wrote:

|Code:
|---------
|C:\> ver
|
|TCC 12.00.29 x64 Windows 7 [Version 6.1.7600]
|
|C:\> set Prog
|ProgramData=C:\ProgramData
|ProgramFiles=C:\Program Files
|ProgramFiles(x86)=C:\Program Files (x86)
|ProgramW6432=C:\Program Files
|
|C:\> echo %ProgramFiles(x86)%
|C:\Program Files(x86)
|
|C:\>
|---------

What you're getting there in the value of %ProgramFiles followed by the literal
string "(x86)" (the trailing '%' contributes nothing).

Get around it like this

Code:
v:\> set ProgramFiles(x86)=C:\Program Files (x86)

v:\> set prog*
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)

v:\> echo %[Programfiles(x86)]
C:\Program Files (x86)
 
CMD behaves correctly:

Perhaps a better phrase would be "CMD behaves as expected, if you don't expect much."

CMD has no idea what a valid variable name is; it simply includes everything between two %'s. If you want TCC to behave the same, set "
CMDVariables=YES" in your TCMD.INI. (Of course, then you'll have to rewrite all of your batch files and aliases.)
 
You can either not use parens, or use the bracketed syntax:
echo %[ProgramFiles(x86)]
I need the parens, because they are in the default environment table on Windows x64.

And this workaround is nice for TC, but it is not CMD-compatible. I might as well use %@shfolder[42].
 
If you want TCC to behave the same, set "CMDVariables=YES" in your TCMD.INI. (Of course, then you'll have to rewrite all of your batch files and aliases.)
Thanks, I may do this. I don't believe I do anything special with environment variables that would need to utilize the better TC parsing....but who knows.
 
Perhaps a better phrase would be "CMD behaves as expected, if you don't expect much."

I wonder how many batch files would be broken by adding parentheses to the list of characters valid in variable names?
 

Similar threads

Back
Top