It is a big difference if an environment variable is defined with set variable="value"
or with set "variable=value"
. Read the answer on Why is no string output with 'echo %var%' after using 'set var = text' on command line? for details.
It is strongly recommended to use set "variable=value"
, i.e. assign the string to the environment variable without double quotes and reference the value of the environment variable always enclosed in double quotes.
It looks like you use:
@ECHO OFF
set JAVA_CMD="C:\Program Files\Java\jdk1.8.0_92\jre\bin\java"
%JAVA_CMD% TransferArborDeereFiles
pause
So to get path of java
executable with having file extension .exe
not specified and therefore Windows command interpreter needs to search for java.*
with a file extension listed in local environment variable PATHEXT
, the following batch code could be used:
@ECHO OFF
set JAVA_CMD="C:\Program Files\Java\jdk1.8.0_92\jre\bin\java"
rem %JAVA_CMD% TransferArborDeereFiles
for /F "delims=" %%I in (%JAVA_CMD%) do set "JAVA_CMD_PATH=%%~dpI"
set JAVA_CMD
pause
This batch file just outputs the values of the environment variables JAVA_CMD
and JAVA_CMD_PATH
.
But much better would be:
@ECHO OFF
setlocal EnableExtensions DisableDelayedExpansion
set "JAVA_CMD=%ProgramFiles%\Java\jdk1.8.0_92\jre\bin\java.exe"
for /F "delims=" %%I in ("%JAVA_CMD%") do set "JAVA_CMD_PATH=%%~dpI"
rem Output all environment variables starting with JAVA_CMD.
set JAVA_CMD
rem "%JAVA_CMD%" TransferArborDeereFiles
rem "%JAVA_CMD_PATH%OtherScriptOrExe" "argument 1" "argument 2"
endlocal
This batch file should be executed in a command prompt window and not with double clicking on the batch file. Debugging a batch file in development should be always done by running it from within a command prompt window to see possible error messages output by Windows command interpreter of errors resulting in exiting batch file execution.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
pause /?
rem /?
set /?
setlocal /?