windows - Unable to rectify the cause during installation of java and setting java path in batch file -
i need install java , set java path. i'm able install java , can see 2 folders in c:\program files (x86)\java i.e jre , jdk .
but when i'm trying set java_path in code can't path on command propmt echo command i.e @echo java_home = %java_home%. though have started scripting today unable rectify i'm missing out ?
here code tried :-
@echo off /f %%j in ("java.exe") ( set java_home=%%~dp$path:j **@echo java_home = %java_home%** echo "ok1" pause ) if %java_home%.==. ( @echo java.exe not found pause cd c:\users\pathfinder\desktop echo "time in" jdk-6u43-windows-i586.exe /s "/v\"/qn addlocal=all reboot=suppress javaupdate=0 custom=1\"" timeout /t 10 /nobreak echo "time out" set path="c:\program files (x86)\java\jre6\bin";%path% @echo path= %path% set java_home="c:\program files (x86)\java\jdk1.6.0_43\bin";%java_home% **@echo java_home = %java_home%** pause ) else ( @echo java_home = %java_home% pause )
after 1 time execution of batch file means process completed after double clicking batch file when i'm again double clicking batch file going 'if' condition again i.e " java.exe not found " .
delayed variable expansion: variables parenthesis evaluated before execution.
here can't use setlocal enabledelayedexpansion
because need variables out of batch.
so must rewrite batch without variables within parenthesis:
@echo off set java_home= /f %%j in ("java.exe") set java_home=%%~dp$path:j if defined java_home goto :java_found :java_not_found @echo java.exe not found pause cd c:\users\pathfinder\desktop echo "time in" jdk-6u43-windows-i586.exe /s "/v\"/qn addlocal=all reboot=suppress javaupdate=0 custom=1\"" timeout /t 10 /nobreak echo "time out" set path="c:\program files (x86)\java\jre6\bin";%path% @echo path= %path% set java_home="c:\program files (x86)\java\jdk1.6.0_43\bin";%java_home% @echo java_home = %java_home% goto :end :java_found @echo java_home = %java_home% echo "ok1" pause @echo java_home = %java_home% pause :end
i left optimization you.
also check start /wait
instead of timeout
.
Comments
Post a Comment