From c75a9b09f6f5dc7fd21731c1f6f70c5034e57771 Mon Sep 17 00:00:00 2001 From: Vyacheslav Moklev Date: Mon, 25 Nov 2019 11:33:39 +0300 Subject: [PATCH] Add prefixes to process arguments in WinProcessListHelper GitOrigin-RevId: f5f21c3fd0cef7f9d568b7d8a0c73e481841a19b --- .../WinProcessListHelper/main.cpp | 10 +++---- .../process/impl/ProcessListUtil.java | 27 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/native/WinProcessListHelper/WinProcessListHelper/main.cpp b/native/WinProcessListHelper/WinProcessListHelper/main.cpp index 862b508539bf..2f09bb5ee11e 100644 --- a/native/WinProcessListHelper/WinProcessListHelper/main.cpp +++ b/native/WinProcessListHelper/WinProcessListHelper/main.cpp @@ -183,19 +183,19 @@ int main(int argc, char **argv) VARIANT vtId; pclsObj->Get(L"ProcessId", 0, &vtId, nullptr, nullptr); - wcout << vtId.intVal << "\n"; + wcout << "pid:" << vtId.intVal << "\n"; VARIANT vtName; pclsObj->Get(L"Name", 0, &vtName, nullptr, nullptr); if (vtName.bstrVal != nullptr) - wcout << escapeLineBreaks(vtName.bstrVal) << L"\n"; + wcout << L"name:" << escapeLineBreaks(vtName.bstrVal) << L"\n"; else - wcout << L"\n"; + wcout << L"name:\n"; VARIANT vtCmd; pclsObj->Get(L"CommandLine", 0, &vtCmd, nullptr, nullptr); if (vtCmd.bstrVal != nullptr) - wcout << L"\"" << escapeLineBreaks(vtCmd.bstrVal) << L"\"\n"; + wcout << L"cmd:" << escapeLineBreaks(vtCmd.bstrVal) << L"\n"; else - wcout << L"\"\"\n"; + wcout << L"cmd:\n"; VariantClear(&vtId); VariantClear(&vtName); VariantClear(&vtCmd); diff --git a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java index aa94920623a8..d957e3a74fc8 100644 --- a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java +++ b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java @@ -278,11 +278,9 @@ public final class ProcessListUtil { } @Nullable - private static String unescapeString(String str, boolean quoted) { + private static String unescapeString(@Nullable String str) { + if (str == null) return null; StringBuilder builder = new StringBuilder(); - if (quoted) { - str = str.substring(1, str.length() - 1); - } for (int index = 0; index < str.length(); index++) { if (str.charAt(index) == '\\') { if (index == str.length() - 1) { @@ -317,6 +315,16 @@ public final class ProcessListUtil { return builder.toString(); } + @Nullable + private static String removePrefix(String str, String prefix) { + if (str.startsWith(prefix)) { + return str.substring(prefix.length()); + } + logErrorTestSafe("Can't remove prefix \"" + prefix + "\""); + LOG.debug(str); + return null; + } + @Nullable static List parseWinProcessListHelperOutput(@NotNull String output) { String[] lines = StringUtil.splitByLines(output, false); @@ -329,7 +337,8 @@ public final class ProcessListUtil { int processCount = lines.length / 3; for (int i = 0; i < processCount; i++) { int offset = i * 3; - int id = StringUtil.parseInt(lines[offset], -1); + String idString = removePrefix(lines[offset], "pid:"); + int id = StringUtil.parseInt(idString, -1); if (id == -1) { logErrorTestSafe("Broken output of " + WIN_PROCESS_LIST_HELPER_FILENAME + ": process ID is not a number: " + lines[offset]); LOG.debug(output); @@ -337,17 +346,17 @@ public final class ProcessListUtil { } if (id == 0) continue; - String name = unescapeString(lines[offset + 1], false); + String name = unescapeString(removePrefix(lines[offset + 1], "name:")); if (name == null) { - logErrorTestSafe("Failed to unescape a process name: " + lines[offset + 1]); + logErrorTestSafe("Failed to read a process name: " + lines[offset + 1]); LOG.debug(output); return null; } if (name.isEmpty()) continue; - String commandLine = unescapeString(lines[offset + 2], true); + String commandLine = unescapeString(removePrefix(lines[offset + 2], "cmd:")); if (commandLine == null) { - logErrorTestSafe("Failed to unescape a process command line: " + lines[offset + 2]); + logErrorTestSafe("Failed to read a process command line: " + lines[offset + 2]); LOG.debug(output); return null; }