Why gives the following Windows 7 .cmd command script:
set SUN_JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_17
if 3==3 (
set JAVA_HOME=%SUN_JAVA_HOME%
)
echo ready
The following error message instead of printing "ready"
\Java\jdk1.6.0_17 was unexpected at this time.
The error message disapears, if I remove the "(x86)" in the path name.
you have to enclose the set command by double quotes
replace
by
because there's a space in the path
The problem is the parentheses grouping after the
if 3==3
part.While parsing the
set JAVA_HOME=%SUN_JAVA_HOME%
command, the interpreter immediately replaces the%SUN_JAVA_HOME%
variable and that causes an early match of the closing parenthesis in(386)
.This can be avoided if you enable delayed expansion and replace
%SUN_JAVA_HOME%
with!SUN_JAVA_HOME!
:I've written about this a while ago (slightly outdated by now).
As an alternative, if you need grouping the commands, then use a subroutine:
Previous answer is ok. I just want clarify it with simple example. It's about detecting Program Files directory for 32-bit application on x86 and x64 systems. There similar problem with "(x86)".
on the command prompt, enter the following commands
This will show you the 8 character name for
Program Files (x86)
Use that name (probably "Progra~2")