# Unable to launch elasticsearch from bat file in windows 10

**URL:** <https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197>\
**Category:** Elasticsearch\
**Tags:** windows\
**Created:** [June 26, 2022, 10:26pm UTC](https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197 "2022-06-26T22:26:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Halim\_Dris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halim_dris/32/107437_2.png) [@Halim\_Dris](https://discuss.elastic.co/u/Halim_Dris)\
**Post date:** [June 26, 2022, 10:26pm UTC](https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197/1 "2022-06-26T22:26:16Z")

</div>

elasticsearch-8.2.3

 ![Sans titre2](https://us1.discourse-cdn.com/elastic/original/3X/1/7/17050b9eebee96a59f5cf5d3f7fe780dfeb3f969.png)

- Running elasticsearch with echo on.

```auto
D:\Elastic\elasticsearch-8.2.3\bin>elasticsearch

D:\Elastic\elasticsearch-8.2.3\bin>setlocal enabledelayedexpansion

D:\Elastic\elasticsearch-8.2.3\bin>setlocal enableextensions

D:\Elastic\elasticsearch-8.2.3\bin>SET params=''

D:\Elastic\elasticsearch-8.2.3\bin>SET checkpassword=Y

D:\Elastic\elasticsearch-8.2.3\bin>SET enrolltocluster=N

D:\Elastic\elasticsearch-8.2.3\bin>SET attemptautoconfig=Y

D:\Elastic\elasticsearch-8.2.3\bin>FOR /F "usebackq tokens=1* delims= " %A IN (!params!) DO (
SET previous=!current!
 SET current=%A
 SET params='%B'
 SET silent=N
 IF "!current!" == "-s" (SET silent=Y )
 IF "!current!" == "--silent" (SET silent=Y )
 IF "!current!" == "-h" (
SET checkpassword=N
 SET attemptautoconfig=N
)
 IF "!current!" == "--help" (
SET checkpassword=N
 SET attemptautoconfig=N
)
 IF "!current!" == "-V" (
SET checkpassword=N
 SET attemptautoconfig=N
)
 IF "!current!" == "--version" (
SET checkpassword=N
 SET attemptautoconfig=N
)
 IF "!current!" == "--enrollment-token" (
IF "!enrolltocluster!" == "Y" (
ECHO "Multiple --enrollment-token parameters are not allowed" 1>&2
 goto exitwithone
)
 SET enrolltocluster=Y
 SET attemptautoconfig=N
)
 IF "!previous!" == "--enrollment-token" (SET enrollmenttoken="!current!" )
 IF "!silent!" == "Y" (SET nopauseonerror=Y ) ELSE (
SET SHOULD_SKIP=false
 IF "!previous!" == "--enrollment-token" SET SHOULD_SKIP=true
 IF "!current!" == "--enrollment-token" SET SHOULD_SKIP=true
 IF "!SHOULD_SKIP!" == "false" (IF "x!newparams!" NEQ "x" (SET newparams=!newparams! !current! ) ELSE (SET newparams=!current! ) )
)
 IF "x!params!" NEQ "x" (GOTO loop )
)

D:\Elastic\elasticsearch-8.2.3\bin>CALL "D:\Elastic\elasticsearch-8.2.3\bin\elasticsearch-env.bat" || exit /b 1

D:\Elastic\elasticsearch-8.2.3\bin>set SCRIPT="D:\Elastic\elasticsearch-8.2.3\bin\elasticsearch-env.bat"

D:\Elastic\elasticsearch-8.2.3\bin>rem determine Elasticsearch home; to do this, we strip from the path until we

D:\Elastic\elasticsearch-8.2.3\bin>rem find bin, and then strip bin (there is an assumption here that there is no

D:\Elastic\elasticsearch-8.2.3\bin>rem nested directory under bin also named bin)

D:\Elastic\elasticsearch-8.2.3\bin>for %I in ("D:\Elastic\elasticsearch-8.2.3\bin\elasticsearch-env.bat") do set ES_HOME=%~dpI

D:\Elastic\elasticsearch-8.2.3\bin>set ES_HOME=D:\Elastic\elasticsearch-8.2.3\bin\

D:\Elastic\elasticsearch-8.2.3\bin>for %I in (":\Elastic\elasticsearch-8.2.3\bin") do set DIRNAME=%~nxI

D:\Elastic\elasticsearch-8.2.3\bin>set DIRNAME=bin

D:\Elastic\elasticsearch-8.2.3\bin>if not "bin" == "bin" (
for %I in ("D:\Elastic\elasticsearch-8.2.3\bin\..") do set ES_HOME=%~dpfI
 goto es_home_loop
)

D:\Elastic\elasticsearch-8.2.3\bin>for %I in ("D:\Elastic\elasticsearch-8.2.3\bin\..") do set ES_HOME=%~dpfI

D:\Elastic\elasticsearch-8.2.3\bin>set ES_HOME=D:\Elastic\elasticsearch-8.2.3

D:\Elastic\elasticsearch-8.2.3\bin>rem now set the classpath

D:\Elastic\elasticsearch-8.2.3\bin>set ES_CLASSPATH=!ES_HOME!\lib\*

D:\Elastic\elasticsearch-8.2.3\bin>set LAUNCHERS_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!\lib\launchers\*

D:\Elastic\elasticsearch-8.2.3\bin>set HOSTNAME=DESKTOP-OB4JG19

D:\Elastic\elasticsearch-8.2.3\bin>if not defined ES_PATH_CONF (set ES_PATH_CONF=!ES_HOME!\config )

D:\Elastic\elasticsearch-8.2.3\bin>rem now make ES_PATH_CONF absolute

D:\Elastic\elasticsearch-8.2.3\bin>for %I in ("D:\Elastic\elasticsearch-8.2.3\config..") do set ES_PATH_CONF=%~dpfI

D:\Elastic\elasticsearch-8.2.3\bin>set ES_PATH_CONF=D:\Elastic\elasticsearch-8.2.3\config

D:\Elastic\elasticsearch-8.2.3\bin>set ES_DISTRIBUTION_FLAVOR=default

D:\Elastic\elasticsearch-8.2.3\bin>set ES_DISTRIBUTION_TYPE=zip

D:\Elastic\elasticsearch-8.2.3\bin>set ES_BUNDLED_JDK=true

D:\Elastic\elasticsearch-8.2.3\bin>if "true" == "false" (echo "warning: no-jdk distributions that do not bundle a JDK are deprecated and will be removed in a future release" 1>&2 )

D:\Elastic\elasticsearch-8.2.3\bin>cd /d "D:\Elastic\elasticsearch-8.2.3"

D:\Elastic\elasticsearch-8.2.3>rem now set the path to java, pass "nojava" arg to skip setting ES_JAVA_HOME and JAVA

D:\Elastic\elasticsearch-8.2.3>if "" == "nojava" (exit /b )

D:\Elastic\elasticsearch-8.2.3>rem comparing to empty string makes this equivalent to bash -v check on env var

D:\Elastic\elasticsearch-8.2.3>rem and allows to effectively force use of the bundled jdk when launching ES

D:\Elastic\elasticsearch-8.2.3>rem by setting ES_JAVA_HOME=

D:\Elastic\elasticsearch-8.2.3>if defined ES_JAVA_HOME (
set JAVA="\bin\java.exe"
 set JAVA_TYPE=ES_JAVA_HOME
) else (
rem use the bundled JDK (default)
 set JAVA="D:\Elastic\elasticsearch-8.2.3\jdk\bin\java.exe"
 set "ES_JAVA_HOME=D:\Elastic\elasticsearch-8.2.3\jdk"
 set JAVA_TYPE=bundled JDK
)

D:\Elastic\elasticsearch-8.2.3>if not exist !JAVA! (
echo "could not find java in !JAVA_TYPE! at !JAVA!" 1>&2
 exit /b 1
)

D:\Elastic\elasticsearch-8.2.3>rem do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)

D:\Elastic\elasticsearch-8.2.3>if defined JAVA_TOOL_OPTIONS (
echo warning: ignoring JAVA_TOOL_OPTIONS=
 set JAVA_TOOL_OPTIONS=
)

D:\Elastic\elasticsearch-8.2.3>rem warn that we are not observing the value of $JAVA_HOME

D:\Elastic\elasticsearch-8.2.3>if defined JAVA_HOME (echo warning: ignoring JAVA_HOME=E:\Program Files\Java\jdk-18.0.1.1; using bundled JDK 1>&2 )
warning: ignoring JAVA_HOME=E:\Program Files\Java\jdk-18.0.1.1; using bundled JDK

D:\Elastic\elasticsearch-8.2.3>rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we

D:\Elastic\elasticsearch-8.2.3>rem warn them that we are not observing the value of

D:\Elastic\elasticsearch-8.2.3>if defined JAVA_OPTS (
(echo | set /p=warning: ignoring JAVA_OPTS=; )
 echo pass JVM parameters via ES_JAVA_OPTS
)

D:\Elastic\elasticsearch-8.2.3>rem check the Java version

D:\Elastic\elasticsearch-8.2.3>"D:\Elastic\elasticsearch-8.2.3\jdk\bin\java.exe" -cp "D:\Elastic\elasticsearch-8.2.3\lib\*;D:\Elastic\elasticsearch-8.2.3\lib\launchers\*" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1

D:\Elastic\elasticsearch-8.2.3>IF ERRORLEVEL 1 (
IF NOT DEFINED nopauseonerror (PAUSE)
 EXIT /B 0
)

D:\Elastic\elasticsearch-8.2.3>SET KEYSTORE_PASSWORD=

D:\Elastic\elasticsearch-8.2.3>IF "Y" == "Y" (
CALL "D:\Elastic\elasticsearch-8.2.3\bin\elasticsearch-keystore.bat" has-passwd --silent
 IF !ERRORLEVEL! EQU 0 (
SET /P KEYSTORE_PASSWORD=Elasticsearch keystore password:
 IF !ERRORLEVEL! NEQ 0 (
ECHO Failed to read keystore password on standard input
 EXIT /B !ERRORLEVEL!
)
)
)
warning: ignoring JAVA_HOME=E:\Program Files\Java\jdk-18.0.1.1; using ES_JAVA_HOME
Le chemin d’accès spécifié est introuvable.

D:\Elastic\elasticsearch-8.2.3\bin>

```

---

<div class="post-metadata">

**Author:** ![sudhagar\_ramesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhagar_ramesh/32/105673_2.png) [@sudhagar\_ramesh](https://discuss.elastic.co/u/sudhagar_ramesh)\
**Post date:** [June 27, 2022, 2:51am UTC](https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197/2 "2022-06-27T02:51:28Z")

</div>

Hello @Halim_Dris

This warning means that you have to set the java 's environmental variable to ES\_JAVA\_HOME

In command prompt just check whether this variable already set or not using this command `echo %ES_JAVA_HOME%`

Could you please set the same in environmental variable under SYSTEM VARIABLE if its not set

---

<div class="post-metadata">

**Author:** ![Halim\_Dris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/halim_dris/32/107437_2.png) [@Halim\_Dris](https://discuss.elastic.co/u/Halim_Dris)\
**Post date:** [June 27, 2022, 8:50pm UTC](https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197/3 "2022-06-27T20:50:17Z")

</div>

> [@sudhagar\_ramesh](#):
>
> echo %ES\_JAVA\_HOME%

- Thank you sudhagar\_ramesh, but the problem come from  
the line 105 of file elasticsearch.bat

> echo %ES\_JAVA\_HOME% = D:\Elastic\elasticsearch-8.2.3\jdk

```auto
ECHO.!KEYSTORE_PASSWORD!| %JAVA% %ES_JAVA_OPTS% ^
      -Des.path.home="%ES_HOME%" ^
      -Des.path.conf="%ES_PATH_CONF%" ^
      -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
      -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
      -cp "!ES_CLASSPATH!;!ES_HOME!/lib/tools/security-cli/*;!ES_HOME!/modules/x-pack-core/*;!ES_HOME!/modules/x-pack-security/*" "org.elasticsearch.xpack.security.cli.AutoConfigureNode" !newparams!

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 25, 2022, 8:51pm UTC](https://discuss.elastic.co/t/unable-to-launch-elasticsearch-from-bat-file-in-windows-10/308197/4 "2022-07-25T20:51:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
