uschindler commented on code in PR #3291:
URL: https://github.com/apache/solr/pull/3291#discussion_r2018383512


##########
solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:
##########
@@ -162,42 +171,60 @@ private static Optional<String> commandLine(ProcessHandle 
ph) {
     if (!Constants.WINDOWS) {
       return ph.info().commandLine();
     } else {
-      long desiredProcessid = ph.pid();
-      try {
-        Process process =
-            new ProcessBuilder(
-                    "wmic",
-                    "process",
-                    "where",
-                    "ProcessID=" + desiredProcessid,
-                    "get",
-                    "commandline",
-                    "/format:list")
-                .redirectErrorStream(true)
-                .start();
-        try (InputStreamReader inputStreamReader =
-                new InputStreamReader(process.getInputStream(), 
StandardCharsets.UTF_8);
-            BufferedReader reader = new BufferedReader(inputStreamReader)) {
-          while (true) {
-            String line = reader.readLine();
-            if (line == null) {
-              return Optional.empty();
-            }
-            if (!line.startsWith("CommandLine=")) {
-              continue;
-            }
-            return Optional.of(line.substring("CommandLine=".length()));
-          }
+      return Optional.ofNullable(pidToWindowsCommandLineMap.get(ph.pid()));
+    }
+  }
+
+  /**
+   * Gets the command lines of all java processes on Windows using PowerShell.
+   *
+   * @return a map of process IDs to command lines
+   */
+  private static Map<Long, String> commandLinesWindows() {
+    try {
+      StopWatch stopWatch = StopWatch.createStarted();
+      Process process =
+          new ProcessBuilder(
+                  "powershell.exe",
+                  "-Command",
+                  "Get-CimInstance -ClassName Win32_Process | Where-Object { 
$_.Name -like '*java*' } | Select-Object ProcessId, CommandLine | 
ConvertTo-Json -Depth 1")
+              .redirectErrorStream(true)
+              .start();
+      try (InputStreamReader inputStreamReader =
+              new InputStreamReader(process.getInputStream(), 
StandardCharsets.UTF_8);

Review Comment:
   Why not directly tell jackson to load the JSON from the `inputStreamReader`? 
To me it looks strange to read it line by line and concat it together. This 
should be the task of the JSON parser.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to