From 261eb5b5ce7b0bac4f2d27b6e3ea23dcf4da72f6 Mon Sep 17 00:00:00 2001 From: tlrx Date: Tue, 6 Jan 2015 15:35:47 +0100 Subject: [PATCH] Windows: makes elasticsearch.bat more friendly to automated processes On Windows platforms when JAVA_HOME is not defined, a message is printed on standard output and the bat script is paused until the user press a key. This behavior is not compliant to automated processes where elasticsearch.bat can be executed by another script. This commit adds a new parameter --silent / -s that allow to skip the pause. Also, the error message is directed to standard and error outputs. Closes #8913 --- bin/elasticsearch.bat | 42 +++++++++++++++++++++++++++++++++++++--- bin/elasticsearch.in.bat | 5 ++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bin/elasticsearch.bat b/bin/elasticsearch.bat index f6e7ba8c0aa..c1f122cf1f7 100644 --- a/bin/elasticsearch.bat +++ b/bin/elasticsearch.bat @@ -1,10 +1,46 @@ @echo off -SETLOCAL +SETLOCAL enabledelayedexpansion TITLE Elasticsearch ${project.version} -CALL "%~dp0elasticsearch.in.bat" +SET params='%*' -"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% %* -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" +:loop +FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( + SET current=%%A + SET params='%%B' + SET silent=N + + IF "!current!" == "-s" ( + SET silent=Y + ) + IF "!current!" == "--silent" ( + SET silent=Y + ) + + IF "!silent!" == "Y" ( + SET nopauseonerror=Y + ) ELSE ( + IF "x!newparams!" NEQ "x" ( + SET newparams=!newparams! !current! + ) ELSE ( + SET newparams=!current! + ) + ) + + IF "x!params!" NEQ "x" ( + GOTO loop + ) +) + +CALL "%~dp0elasticsearch.in.bat" +IF ERRORLEVEL 1 ( + IF NOT DEFINED nopauseonerror ( + PAUSE + ) + EXIT /B %ERRORLEVEL% +) + +"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% !newparams! -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" ENDLOCAL diff --git a/bin/elasticsearch.in.bat b/bin/elasticsearch.in.bat index 6dbca4fdd25..567bec6ee77 100644 --- a/bin/elasticsearch.in.bat +++ b/bin/elasticsearch.in.bat @@ -3,9 +3,8 @@ if DEFINED JAVA_HOME goto cont :err -echo JAVA_HOME environment variable must be set! -pause -exit +ECHO JAVA_HOME environment variable must be set! 1>&2 +EXIT /B 1 :cont set SCRIPT_DIR=%~dp0