diff --git a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java index 96301756e..dab263a05 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java +++ b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java @@ -90,35 +90,28 @@ public class ProcessUtils { private static Map listProcessByJps(boolean v) { Map result = new LinkedHashMap(); - File jps = findJps(); - if (jps == null) { - return result; + String jps = "jps"; + File jpsFile = findJps(); + if (jpsFile != null) { + jps = jpsFile.getAbsolutePath(); } String[] command = null; if (v) { - command = new String[] { jps.getAbsolutePath(), "-v" }; + command = new String[] { jps, "-v" }; } else { - command = new String[] { jps.getAbsolutePath() }; + command = new String[] { jps }; } - ProcessBuilder pb = new ProcessBuilder(command); - try { - Process proc = pb.start(); - BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); - - // read the output from the command - String line = null; - int currentPid = Integer.parseInt(ProcessUtils.getPid()); - while ((line = stdInput.readLine()) != null) { - int pid = new Scanner(line).nextInt(); - if (pid == currentPid) { - continue; - } - result.put(pid, line); + List lines = ExecutingCommand.runNative(command); + + int currentPid = Integer.parseInt(ProcessUtils.getPid()); + for (String line : lines) { + int pid = new Scanner(line).nextInt(); + if (pid == currentPid) { + continue; } - } catch (Throwable e) { - // ignore + result.put(pid, line); } return result;