use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListUtil method parseListTasksOutput.
@Nullable
static List<ProcessInfo> parseListTasksOutput(@NotNull String output) {
List<ProcessInfo> result = ContainerUtil.newArrayList();
CSVReader reader = new CSVReader(new StringReader(output));
try {
String[] next;
while ((next = reader.readNext()) != null) {
if (next.length < 2)
return null;
int pid = StringUtil.parseInt(next[1], -1);
if (pid == -1)
continue;
String name = next[0];
if (name.isEmpty())
continue;
result.add(new ProcessInfo(pid, name, name, ""));
}
} catch (IOException e) {
LOG.error("Cannot parse listtasks output", e);
return null;
} finally {
try {
reader.close();
} catch (IOException ignore) {
}
}
return result;
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListUtil method parseWinNativeHelperOutput.
private static List<ProcessInfo> parseWinNativeHelperOutput(String output) throws IllegalStateException {
String[] strings = StringUtil.splitByLines(output, false);
ArrayList<ProcessInfo> result = new ArrayList<>();
int processCount = strings.length / 3;
for (int i = 0; i < processCount; i++) {
int offset = i * 3;
int id = StringUtil.parseInt(strings[offset], -1);
if (id == -1 || id == 0)
continue;
String name = strings[offset + 1];
if (StringUtil.isEmpty(name))
continue;
String commandLine = strings[offset + 2];
String args;
if (commandLine.isEmpty()) {
commandLine = name;
args = "";
} else {
args = extractCommandLineArgs(commandLine, name);
}
result.add(new ProcessInfo(id, commandLine, name, args));
}
return result;
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListUtil method parseMacOutput.
@Nullable
static List<ProcessInfo> parseMacOutput(String commandOnly, String full) {
List<MacProcessInfo> commands = doParseMacOutput(commandOnly);
List<MacProcessInfo> fulls = doParseMacOutput(full);
if (commands == null || fulls == null)
return null;
TIntObjectHashMap<String> idToCommand = new TIntObjectHashMap<>();
for (MacProcessInfo each : commands) {
idToCommand.put(each.pid, each.commandLine);
}
List<ProcessInfo> result = new ArrayList<>();
for (MacProcessInfo each : fulls) {
if (!idToCommand.containsKey(each.pid))
continue;
String command = idToCommand.get(each.pid);
if (!(each.commandLine.equals(command) || each.commandLine.startsWith(command + " ")))
continue;
String name = PathUtil.getFileName(command);
String args = each.commandLine.substring(command.length()).trim();
result.add(new ProcessInfo(each.pid, each.commandLine, name, args, command));
}
return result;
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListTest method testMac_DoNotIncludeZombies.
public void testMac_DoNotIncludeZombies() throws Exception {
List<ProcessInfo> infos = ProcessListUtil.parseMacOutput(" PID STAT USER COMM\n\n" + " 1 S user /dir/file\n" + " 2 Z user /dir/file\n" + " 3 SZ user /dir/file\n", " PID STAT USER COMMAND\n\n" + " 1 S user /dir/file\n" + " 2 Z user /dir/file\n" + " 3 SZ user /dir/file\n");
assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"));
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListTest method testMac_Basic.
public void testMac_Basic() throws Exception {
List<ProcessInfo> infos = ProcessListUtil.parseMacOutput(" PID STAT USER COMM\n\n" + " 1 S user /dir/file\n" + " 2 S user ./dir/dir/file\n" + " 3 S user ./dir/dir/file\n", " PID STAT USER COMMAND\n\n" + " 1 S user /dir/file\n" + " 2 S user ./dir/dir/file\n" + " 3 S user ./dir/dir/file param param");
assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"), new ProcessInfo(2, "./dir/dir/file", "file", "", "./dir/dir/file"), new ProcessInfo(3, "./dir/dir/file param param", "file", "param param", "./dir/dir/file"));
}
Aggregations