Environment variable oddity

May 26, 2008
541
4
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:\>
 
May 26, 2008
541
4
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:\>
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
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:\>
> ---------
>
>
>
 
May 26, 2008
541
4
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.
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
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:\>
> ---------
>
>
>
 
May 20, 2008
11,547
107
Syracuse, NY, USA
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)
 

rconn

Administrator
Staff member
May 14, 2008
12,406
152
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.)
 
May 26, 2008
541
4
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].
 
May 26, 2008
541
4
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.
 
Similar threads
Thread starter Title Forum Replies Date
J Set environment variable from stdout of command Support 3
nickles Passing a variable to a command w/o adding it to the local environment Support 7
rfaquino WAD Apparently a bug when expanding environment variable %ProgramFiles(x86) Support 2
B WAD environment variable in TCC.exe Support 2
M Updating environment variable from C++ fails erratically in version 14... Support 57
Frank problem with environment variable x86 vs. x64 Support 2
S blanks in environment variable paths Support 4
E Environment variable in tcmd.ini Support 14
I Environment variable in OPTION screen? Support 2
J trouble redirecting output to environment variable Support 7
Peter Murschall v27.00.16/17: ENDLOCAL with exporting variables wipes out the complete Environment Support 2
T Is there a way to maintain the position in the environment list, while debugging? Support 10
D Unnecessary environment dependencies of TCC.EXE Support 3
T Portable Take Command installation for VDI environment Support 2
D v23 environment oddity Support 3
gschizas Take Command (Environment) doesn't show v2 ANSI colors Support 30
M Save the environment .. ;-) Support 2
Charles Dye Read-only environment variables wiped by SETLOCAL / ENDLOCAL Support 5
J Shell nesting level, and inherited environment variables Support 10
vefatica Environment refresh? Support 0
SeoulBigChris Save Environment (Tabs) on Exit? Support 3
fpefpe Documentation environment variables Support 3
fpefpe How to? Environment Variables changed Support 2
vefatica OT: Rex, how does CMD handle its environment? Support 0
fpefpe volatile environment Support 5
daniel347x How to get Take Command to read in all current system environment variables that CMD.EXE sees? Support 13
D Environment in elevated process Support 1
Peter Bratton IDE environment window display Support 0
vefatica Got IDE's environment tab back Support 0
vefatica What environment variables does IDE need? Support 3
tinjaw Looking for best practice for custom environment on tabs Support 0
E Environment variables, set and input Support 2
D Parsing an array variable to an array does not work Support 5
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
P Inserting string into a variable. Support 3
vefatica Setting array variable ignores leading spaces (and @execarray doesn't) Support 4
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R Difference between TCC and CMD: variable names with hyphens Support 4
Joe Caverly Get a variable type Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
rps For loop internal %_for_files variable? Support 2
A How to safely print variable's value without quotes? Support 9
vefatica Array name in a variable? Support 3
nikbackm TCC 20 variable expansion bug Support 6
X How to set %_INIREAD result to variable Support 5
Charles Dye _USBS variable Support 2
BeechComer Debugger: how to set %1 variable? Support 3
Mordachai Variable followed by function constantly failing... Support 5
T Variable indirection for arrays Support 1
Mike Hall Unexpected "Variable loop" in IF condition Support 10

Similar threads