mardi 21 juin 2016

Updating env variables in batch

Here is how I try to update an evironment variable JAVA_HOME

if "%JAVA_HOME%" == "" (
    where java > java_path
    echo File contents is
    type java_path
    set /p JAVA_HOME=< java_path
    echo %JAVA_HOME:~0,-13%
    set JAVA_HOME=%JAVA_HOME:~0,-13%
)

The output I get is

File contents is
C:\Program Files (x86)\Java\jre7\bin\java.exe
~0,-13

I am getting weird ~0,-13 instead of C:\Program Files (x86)\Java\jre7 which is expected because where java is C:\Program Files (x86)\Java\jre7\bin\java.exe

Curiously, it succeeds if I remove if "%JAVA_HOME%" = "" condition.

Aucun commentaire:

Enregistrer un commentaire