Fix IDEA-228371: use UTF-8 for WinProcessListHelper output

GitOrigin-RevId: 79af877e65887e2f89f753e9e313729d94d5870b
This commit is contained in:
Ivan Migalev
2019-12-04 17:00:06 +03:00
committed by intellij-monorepo-bot
parent 1574e05d22
commit 6e290f092a
3 changed files with 17 additions and 2 deletions

Binary file not shown.

View File

@@ -5,6 +5,8 @@ using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
#include <string>
#include <io.h>
#include <fcntl.h>
#pragma comment(lib, "wbemuuid.lib")
@@ -29,6 +31,8 @@ wstring escapeLineBreaks(const wstring& str)
int main(int argc, char **argv)
{
_setmode(_fileno(stdout), _O_U8TEXT);
HRESULT hres;
// Step 1: --------------------------------------------------

View File

@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -73,9 +74,19 @@ public final class ProcessListUtil {
@Nullable
private static List<ProcessInfo> parseCommandOutput(@NotNull List<String> command,
@NotNull NullableFunction<? super String, ? extends List<ProcessInfo>> parser) {
return parseCommandOutput(command, parser, null);
}
@Nullable
private static List<ProcessInfo> parseCommandOutput(@NotNull List<String> command,
@NotNull NullableFunction<? super String, ? extends List<ProcessInfo>> parser,
@Nullable Charset charset) {
String output;
try {
ProcessOutput processOutput = ExecUtil.execAndGetOutput(new GeneralCommandLine(command));
GeneralCommandLine commandLine = new GeneralCommandLine(command);
if (charset != null)
commandLine.withCharset(charset);
ProcessOutput processOutput = ExecUtil.execAndGetOutput(commandLine);
int exitCode = processOutput.getExitCode();
if (exitCode != 0) {
LOG.error("Cannot get process list, command '" + StringUtil.join(command, " ") +"' exited with code " + exitCode + ", stdout:\n"
@@ -265,7 +276,7 @@ public final class ProcessListUtil {
if (exeFile == null) {
return null;
}
return parseCommandOutput(Collections.singletonList(exeFile.getAbsolutePath()), ProcessListUtil::parseWinProcessListHelperOutput);
return parseCommandOutput(Collections.singletonList(exeFile.getAbsolutePath()), ProcessListUtil::parseWinProcessListHelperOutput, StandardCharsets.UTF_8);
}
private static void logErrorTestSafe(String message) {