Skip to content

Commit 53b9ff8

Browse files
authored
Fix handling of spaces in Windows paths
This commit fixes the handling of spaces in Windows paths. The current mechanism works fine in a path that contains a single space, but fails on a path that contains multiple spaces. With this commit, that is no longer the case. Relates #21921
1 parent b9df2e2 commit 53b9ff8

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

distribution/src/main/resources/bin/elasticsearch-service.bat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ SETLOCAL enabledelayedexpansion
44
TITLE Elasticsearch Service ${project.version}
55

66
IF DEFINED JAVA_HOME (
7-
SET JAVA=%JAVA_HOME%\bin\java.exe
7+
SET JAVA="%JAVA_HOME%"\bin\java.exe
88
) ELSE (
99
FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I
1010
)
11-
IF NOT EXIST "%JAVA%" (
11+
IF NOT EXIST %JAVA% (
1212
ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2
1313
EXIT /B 1
1414
)
1515
IF DEFINED JAVA_HOME GOTO :cont
1616

17-
IF NOT "%JAVA:~-13%" == "\bin\java.exe" (
17+
IF NOT %JAVA:~-13% == "\bin\java.exe" (
1818
FOR /f "tokens=2 delims=[]" %%I IN ('dir %JAVA%') DO @set JAVA=%%I
1919
)
20-
IF "%JAVA:~-13%" == "\bin\java.exe" (
20+
IF %JAVA:~-13% == "\bin\java.exe" (
2121
SET JAVA_HOME=%JAVA:~0,-13%
2222
)
2323

@@ -27,14 +27,14 @@ if not "%CONF_FILE%" == "" goto conffileset
2727
set SCRIPT_DIR=%~dp0
2828
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI
2929

30-
"%JAVA%" -Xmx50M -version > nul 2>&1
30+
%JAVA% -Xmx50M -version > nul 2>&1
3131

3232
if errorlevel 1 (
3333
echo Warning: Could not start JVM to detect version, defaulting to x86:
3434
goto x86
3535
)
3636

37-
"%JAVA%" -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
37+
%JAVA% -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
3838

3939
if errorlevel 1 goto x86
4040
set EXECUTABLE=%ES_HOME%\bin\elasticsearch-service-x64.exe

distribution/src/main/resources/bin/elasticsearch.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ IF ERRORLEVEL 1 (
5454
EXIT /B %ERRORLEVEL%
5555
)
5656

57-
"%JAVA%" %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
57+
%JAVA% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
5858

5959
ENDLOCAL

distribution/src/main/resources/bin/elasticsearch.in.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@echo off
22

33
IF DEFINED JAVA_HOME (
4-
set JAVA=%JAVA_HOME%\bin\java.exe
4+
set JAVA="%JAVA_HOME%"\bin\java.exe
55
) ELSE (
66
FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I
77
)
8-
IF NOT EXIST "%JAVA%" (
8+
IF NOT EXIST %JAVA% (
99
ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2
1010
EXIT /B 1
1111
)

0 commit comments

Comments
 (0)