@@ -160,32 +160,32 @@ private void validateFunctionRuntime(RunProcessHandler processHandler) throws Az
160160 if (funcVersion .compareTo (minimumVersion ) < 0 ) {
161161 throw new AzureExecutionException (FUNCTION_CORE_TOOLS_OUT_OF_DATE );
162162 }
163- } catch (IOException | InterruptedException e ) {
163+ } catch (IOException e ) {
164164 throw new AzureExecutionException (String .format (FAILED_TO_VALIDATE_FUNCTION_RUNTIME , e .getMessage ()));
165165 }
166166 }
167167
168- private ComparableVersion getFuncVersion () throws IOException , InterruptedException {
168+ private ComparableVersion getFuncVersion () throws IOException {
169169 final File func = new File (functionRunConfiguration .getFuncPath ());
170- final String [] funcVersionResult = CommandUtils .executeMultipleLineOutput (
171- String .format ("%s -v" , func .getName ()), func .getParentFile ());
172- if (ArrayUtils .isEmpty (funcVersionResult )) {
170+ final String funcVersion = CommandUtils .executeCommandAndGetOutput (func .getAbsolutePath (), new String []{"-v" }, func .getParentFile ());
171+ if (StringUtils .isEmpty (funcVersion )) {
173172 return null ;
174173 }
175- return new ComparableVersion (funcVersionResult [ 0 ]. trim () );
174+ return new ComparableVersion (funcVersion );
176175 }
177176
178177 // Get java runtime version following the strategy of function core tools
179178 // Get java version of JAVA_HOME first, fall back to use PATH if JAVA_HOME not exists
180- private ComparableVersion getJavaVersion () throws IOException , InterruptedException {
179+ private ComparableVersion getJavaVersion () throws IOException {
181180 final String javaHome = System .getenv ("JAVA_HOME" );
182- final File executeFolder = StringUtils .isEmpty (javaHome ) ? null : Paths .get (javaHome , "bin" ).toFile ();
183- final String [] javaVersionResult = CommandUtils .executeMultipleLineOutput (
184- "java -version" , executeFolder , Process ::getErrorStream ); // java -version will write to std error
185- if (ArrayUtils .isEmpty (javaVersionResult )) {
181+ final File javaFile = StringUtils .isEmpty (javaHome ) ? null : Paths .get (javaHome , "bin" , "java" ).toFile ();
182+ final File executeFolder = javaFile == null ? null : javaFile .getParentFile ();
183+ final String command = javaFile == null ? "java" : javaFile .getAbsolutePath ();
184+ final String javaVersion = CommandUtils .executeCommandAndGetOutput (command , new String []{"-version" }, executeFolder );
185+ if (StringUtils .isEmpty (javaVersion )) {
186186 return null ;
187187 }
188- final Matcher matcher = JAVA_VERSION_PATTERN .matcher (javaVersionResult [ 0 ]. trim () );
188+ final Matcher matcher = JAVA_VERSION_PATTERN .matcher (javaVersion );
189189 return matcher .find () ? new ComparableVersion (matcher .group (1 )) : null ;
190190 }
191191
0 commit comments