The system can not find the specified path (batch file) - Use path with whitespace - PENTAHO spoon.bat (pdi-ce-


I'm trying to execute a batch file "spoon.bat" from PENTAHO (pdi-ce-, but there is an error.

Part of batch file where the error is found:

if "%SPOON_CONSOLE%"=="1" set PENTAHO_JAVA=C:\Program Files (x86)\Java\jre1.8.0_121\bin\java.exe
if not "%SPOON_CONSOLE%"=="1" set PENTAHO_JAVA=C:\Program Files (x86)\Java\jre1.8.0_121\bin\javaw.exe
call "%~dp0set-pentaho-env.bat"

But I receive next below error:

The system cannot find the path specified

The error is when I'm trying to assign the path where java.exe or javaw.exe are found to "PENTAHO_JAVA".

I've modified the path with double quote mark, but doesn't work; and also I've modified as:

if "%SPOON_CONSOLE%"=="1" set "PENTAHO_JAVA=C:\<Program Files (x86)>\Java\jre1.8.0_121\bin\java.exe"

Any idea to how declare it to fix it?

Where is the environment variable PENTAHO_JAVA referenced?

It must be referenced with "%PENTAHO_JAVA%" because the string assigned to this environment variable contains characters like a space or &()[]{}^=;!'+,`~. This is explained in help of Windows command interpreter output on running in a command prompt window cmd /? in last paragraph on last help page.

It is of course also possible to define the environment variable with the necessary double quotes already added, i.e. use:

if     "%SPOON_CONSOLE%"=="1" set "PENTAHO_JAVA="%ProgramFiles(x86)%\Java\jre1.8.0_121\bin\java.exe""
if not "%SPOON_CONSOLE%"=="1" set "PENTAHO_JAVA="%ProgramFiles(x86)%\Java\jre1.8.0_121\bin\javaw.exe""
set "IS64BITJAVA=0"
call "%~dp0set-pentaho-env.bat"

But this is not recommended. Better would be to use

if     "%SPOON_CONSOLE%"=="1" set "PENTAHO_JAVA=%ProgramFiles(x86)%\Java\jre1.8.0_121\bin\java.exe"
if not "%SPOON_CONSOLE%"=="1" set "PENTAHO_JAVA=%ProgramFiles(x86)%\Java\jre1.8.0_121\bin\javaw.exe"
set "IS64BITJAVA=0"
call "%~dp0set-pentaho-env.bat"

and reference environment variable PENTAHO_JAVA enclosed in double quotes where it is necessary to specify its value enclosed in double quotes.


@echo off
rem Get path of latest installed Java directly from Windows registry.
for /F "skip=1 tokens=1,2*" %%N in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\javaws.exe" /v Path 2^>nul') do if /I "%%N" == "Path" set "PENTAHO_JAVA=%%P" & goto JavaPathFound

rem Path of Java not found in registry, search for 32-bit Java in the default
rem program files folders of 64-bit and 32-bit Windows and take first found.
if "%ProgramFiles(x86)%" == "" goto Windows_x86
for /R "%ProgramFiles(x86)%" %%I in (java*.exe) do set "PENTAHO_JAVA=%%~dpI" & goto JavaPathFound
for /R "%ProgramFiles%" %%I in (java*.exe) do set "PENTAHO_JAVA=%%~dpI" & goto JavaPathFound

echo Error: Java binary directory not found.
goto :EOF

echo Error: File %PENTAHO_JAVA% not found.
goto :EOF

if not "%PENTAHO_JAVA:~-1%" == "\" set "PENTAHO_JAVA=%PENTAHO_JAVA%\"
if "%SPOON_CONSOLE%" == "1" (
    set "PENTAHO_JAVA=%PENTAHO_JAVA%java.exe"
) else (
    set "PENTAHO_JAVA=%PENTAHO_JAVA%javaw.exe"

rem Check existence of Java executable to run.
if not exist "%PENTAHO_JAVA%" goto ErrorJavaEXE

"%PENTAHO_JAVA%" -version
call "%~dp0set-pentaho-env.bat"

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.

  • call /?
  • echo /?
  • for /?
  • goto /?
  • if /?
  • pause /?
  • reg /?
  • reg query /?
  • rem /?

Read also the Microsoft article about Using Command Redirection Operators for an explanation of 2>nul whereby redirection operator must be escaped in this batch code on FOR command line with caret character ^. And read answer on Single line with multiple commands using Windows batch file for an explanation of & operator.