Reputation: 141
On Windows 8.1 I am installing a program which looks for the Java vm location.
It runs without any problem with these environment variables set manually:
JAVA_HOME="C:\Program Files (x86)\Java\jre1.8.0_102"
PATH=%JAVA_HOME%\bin
It does NOT run with this:
JAVA_HOME="C:\Program Files (x86)\Java\jre1.8.0_102"
PATH=%JAVA_HOME%\bin;%PATH%
Where I have written %PATH%
above means all other necessary system paths separated with semicolons etc.
The program can only find the jvm when PATH
is a single directory entry.
I have tried running the program from a batch file and temporarily changing the PATH
. I understand that the temporary change only exists while that command screen is open.
This is my batch file:
set PATH=%JAVA_HOME%\bin
start Epson_JavaPOS_1.1.4 blah blah.exe
cmd /K
Problem is I think the temp value is not being retained when the program installation starts and user input is detected.
How can I accomplish this?
Upvotes: 0
Views: 39
Reputation: 141
@Mofi - I found your information extremely helpful and so led me in the right direction. Here is the solution to my question of how i can automate the installation of the program that cant find the Java vm...
The program WILL find the jvm when the jvm path is APPENDED to %PATH% instead of PREPENDED.
Batch script amendment:
Example 1
setx JAVA_HOME "%ProgramFiles(x86)%\Java\jre1.8.0_102"
setx PATH "%JAVA_HOME%\bin"
start Epson_JavaPOS_ADK_1141.exe
cmd /K
OR THIS (as Mofi suggested)
Example 2
set "JAVA_HOME=%ProgramFiles(x86)%\Java\jre1.8.0_102"
if "%PATH:~-1%" == ";" (
set "PATH=%PATH%%JAVA_HOME%\bin"
) else (
set "PATH=%PATH%;%JAVA_HOME%\bin"
)
start Epson_JavaPOS_ADK_1141.exe
cmd /K
In Example 2, %JAVA_HOME%\bin is appended to PATH variable twice.
In Example 1:
This line:
setx JAVA_HOME "%ProgramFiles(x86)%\Java\jre1.8.0_102"
creates a User variable which overrides any System variable.(In my case, none)
This line:
setx PATH "%JAVA_HOME%\bin"
creates a User variable which appends to PATH System variable.
Upvotes: 0
Reputation: 49096
Please read the answers on
for an explanation why set variable="string with space"
is most often not good like here with variable value with the double quotes being concatenated next with another string.
The first script code in question would produce on expansion the PATH
variable with value:
"C:\Program Files (x86)\Java\jre1.8.0_102"\bin
which is definitely not right.
But it does not even produce this string as the command set
is also missing in both lines. For that reason Windows command processor outputs on execution of the first line just an error message as it can't find an application, script or internal command with name JAVA_HOME
. The second line does not result in an error message because of command PATH resulting in local environment variable PATH
being redefined with value \bin
.
Use this code to append the path to Java home directory to PATH
:
set "JAVA_HOME=%ProgramFiles(x86)%\Java\jre1.8.0_102"
if "%PATH:~-1%" == ";" (
set "PATH=%PATH%%JAVA_HOME%\bin"
) else (
set "PATH=%PATH%;%JAVA_HOME%\bin"
)
Use this code to prepend the path to Java home directory to PATH
:
set "JAVA_HOME=%ProgramFiles(x86)%\Java\jre1.8.0_102"
set "PATH=%JAVA_HOME%\bin;%PATH%"
The semicolon separated directory paths within string value of environment variable PATH
are not double quoted even when a directory path contains 1 or more spaces or parentheses.
There is only one exception on which a directory path must be added to PATH
with double quotes: the directory path contains itself 1 or even more semicolons.
Run in a command prompt window set /?
or help set
for help on command SET.
Upvotes: 1