Skip to content

Commit 87efb51

Browse files
authored
Fix getJavaVersion not work issue (#4624)
1 parent c2a94b0 commit 87efb51

File tree

2 files changed

+16
-4
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/functions/localrun
  • Utils/azuretools-core/src/com/microsoft/azuretools/utils

2 files changed

+16
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/runner/functions/localrun/FunctionRunState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ private ComparableVersion getJavaVersion() throws IOException {
201201
final File javaFile = StringUtils.isEmpty(javaHome) ? null : Paths.get(javaHome, "bin", "java").toFile();
202202
final File executeFolder = javaFile == null ? null : javaFile.getParentFile();
203203
final String command = javaFile == null ? "java" : javaFile.getAbsolutePath();
204-
final String javaVersion = CommandUtils.executeCommandAndGetOutput(command, new String[]{"-version"}, executeFolder);
204+
final String javaVersion = CommandUtils.executeCommandAndGetOutput(command, new String[]{"-version"},
205+
executeFolder, true);
205206
if (StringUtils.isEmpty(javaVersion)) {
206207
return null;
207208
}

Utils/azuretools-core/src/com/microsoft/azuretools/utils/CommandUtils.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ public static String exec(final String commandWithArgs) throws IOException {
8787
}
8888

8989
public static String executeCommandAndGetOutput(final String commandWithoutArgs, final String[] args, final File directory) throws IOException {
90+
return executeCommandAndGetOutput(commandWithoutArgs, args, directory, false);
91+
}
92+
93+
public static String executeCommandAndGetOutput(final String commandWithoutArgs, final String[] args, final File directory,
94+
final boolean mergeErrorStream) throws IOException {
9095
final CommandLine commandLine = new CommandLine(commandWithoutArgs);
9196
commandLine.addArguments(args);
92-
return executeCommandAndGetOutput(commandLine, directory);
97+
return executeCommandAndGetOutput(commandLine, directory, mergeErrorStream);
9398
}
9499

95100
public static String executeCommandAndGetOutput(final String starter, final String switcher, final String commandWithArgs,
@@ -101,16 +106,22 @@ public static String executeCommandAndGetOutput(final String starter, final Stri
101106
}
102107

103108
public static String executeCommandAndGetOutput(final CommandLine commandLine, final File directory) throws IOException {
109+
return executeCommandAndGetOutput(commandLine, directory, false);
110+
}
111+
112+
public static String executeCommandAndGetOutput(final CommandLine commandLine, final File directory, final boolean mergeErrorStream) throws IOException {
104113
final ByteArrayOutputStream out = new ByteArrayOutputStream();
105-
final ByteArrayOutputStream err = new ByteArrayOutputStream();
114+
final ByteArrayOutputStream err = mergeErrorStream ? out : new ByteArrayOutputStream();
106115
final PumpStreamHandler streamHandler = new PumpStreamHandler(out, err);
107116
final DefaultExecutor executor = new DefaultExecutor();
108117
executor.setWorkingDirectory(directory);
109118
executor.setStreamHandler(streamHandler);
110119
executor.setExitValues(null);
111120
try {
112121
executor.execute(commandLine);
113-
logger.log(Level.SEVERE, err.toString());
122+
if (!mergeErrorStream) {
123+
logger.log(Level.SEVERE, err.toString());
124+
}
114125
return out.toString();
115126
} catch (ExecuteException e) {
116127
// swallow execute exception and return empty

0 commit comments

Comments
 (0)