Skip to content

Conversation

@jasontedor
Copy link
Member

@jasontedor jasontedor commented Dec 1, 2016

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 #20809, relates #21525

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.
@jasontedor jasontedor added :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts >bug review v5.0.3 v5.2.0 v6.0.0-alpha1 labels Dec 1, 2016
@jasontedor
Copy link
Member Author

I've manually tested this for both running Elasticsearch from the command line and the service, and with paths that contain zero, one, two, and three spaces and everything works as expected.

Copy link

@ngbrown ngbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When setting environment variables, the full path should be included in the quotes.


IF DEFINED JAVA_HOME (
set JAVA=%JAVA_HOME%\bin\java.exe
set JAVA="%JAVA_HOME%"\bin\java.exe
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quotes should surround the entire path, including the .exe.


IF DEFINED JAVA_HOME (
SET JAVA=%JAVA_HOME%\bin\java.exe
SET JAVA="%JAVA_HOME%"\bin\java.exe
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quotes should surround the entire path, including the .exe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I tested it with this change. Do you have an example where this would break without your suggestion?

@rjernst
Copy link
Member

rjernst commented Dec 1, 2016

This LGTM. Should we consider (in a follow up) having our integ test dir which contains a space have two spaces (I did not realize it was possible to have different behavior for one vs two spaces).

@jasontedor
Copy link
Member Author

Should we consider (in a follow up) having our integ test dir which contains a space have two spaces (I did not realize it was possible to have different behavior for one vs two spaces)

Yes, I was thinking the same thing. Lacking packaging tests, that's test best that we can do but it's been really effective for us in the past.

@jasontedor jasontedor merged commit 53b9ff8 into elastic:master Dec 2, 2016
jasontedor added a commit that referenced this pull request Dec 2, 2016
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
jasontedor added a commit that referenced this pull request Dec 2, 2016
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
jasontedor added a commit that referenced this pull request Dec 2, 2016
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
@jasontedor jasontedor deleted the double-the-spaces-double-the-trouble branch December 2, 2016 01:41
@jasontedor
Copy link
Member Author

Thanks @rjernst.

@yannlebel
Copy link

When I read this it seems the issue is not closed and included in a release package but when I download the elasticsearch zip from here https://www.elastic.co/downloads/elasticsearch it's already included. Did something went wrong?

This fix in not working for me. I tested the version 5.1.1 on windows 7 (x64) and windows server 2012 R2 (x64) standard and had the same issue every time.

The quote around the %JAVA_HOME% and %JAVA% variables are not placed correctly which prevent the scripts to start the node and to detect the JVM version which always default the service installation to the x86 version.

My JAVA_HOME variable is set with the value: C:\Program Files\Java\jdk1.8.0_111
My installation folder for elasticsearch is: D:\ELK\elasticsearch\

######Result of the elasticsearch.bat execution before the fix:
image

######Result of the elasticsearch-service.bat execution before the fix:
image

To fix the problem I had to do the following changes:

  • In elastisearch.bat
    • Line 82
      • From: %JAVA% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
      • To: "%JAVA%" %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
  • In elasticsearch.in.bat
    • Line 4
      • From: set JAVA="%JAVA_HOME%"\bin\java.exe
      • To: set JAVA=%JAVA_HOME%\bin\java.exe
    • Line 8
      • From: IF NOT EXIST %JAVA% (
      • To: IF NOT EXIST "%JAVA%" (
  • In Elasticsearch-service.bat
    • Line 32
      • From: SET JAVA="%JAVA_HOME%"\bin\java.exe
      • To: SET JAVA=%JAVA_HOME%\bin\java.exe
    • Line 36
      • From: IF NOT EXIST %JAVA% (
      • To: IF NOT EXIST "%JAVA%" (
    • Line 55
      • From: %JAVA% -Xmx50M -version > nul 2>&1
      • To: "%JAVA%" -Xmx50M -version > nul 2>&1
    • Line 62
      • From: %JAVA% -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
      • To: "%JAVA%" -Xmx50M -version 2>&1 | "%windir%\System32\find" "64-Bit" >nul:
    • Line 149
      • From: if exist "%JAVA_HOME%"\jre\bin\server\jvm.dll (
      • To: if exist "%JAVA_HOME%\jre\bin\server\jvm.dll" (
    • Line 155
      • From: if exist "%JAVA_HOME%"\bin\server\jvm.dll (
      • To: if exist "%JAVA_HOME%\bin\server\jvm.dll" (
    • Line 161
      • From: if exist "%JAVA_HOME%"\bin\client\jvm.dll (
      • To: if exist "%JAVA_HOME%\bin\client\jvm.dll" (

Here are the files with the fixes:

elasticsearch-service.bat.txt
elasticsearch.bat.txt
elasticsearch.in.bat.txt

Hope it helps.

@jasontedor
Copy link
Member Author

@yannlebel If you remove the trailing backslash from JAVA_HOME, what is packaged today works fine. There is an open PR (#22132) to address this.

@yannlebel
Copy link

Sorry my mistake I didn't read the changes in the commit correctly and thought this was the PR and #22132 was an issue. I tried without the trailing slash and indead it is working.

@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts Team:Delivery Meta label for Delivery team v5.0.3 v5.1.1 v5.2.0 v6.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants