tags:

views:

135

answers:

3

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.

A: 

on the command prompt, enter the following commands

C:
CD\
dir /ogen /x

This will show you the 8 character name for Program Files (x86)

Use that name (probably "Progra~2")

Raj More
A: 

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!:

setlocal enabledelayedexpansion

set SUN_JAVA_HOME=C[link text][1]:\Program Files (x86)\Java\jdk1.6.0_17

if 3==3 (
    set JAVA_HOME=!SUN_JAVA_HOME!
)
echo ready
efotinis
A: 

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:

if 3==3 call :foo
...
goto :eof
:foo
...
goto :eof
Joey