IDEA-131748 Stop debug session kills all processes - read taskkill output and log in case of error

This commit is contained in:
Egor.Ushakov
2016-05-06 18:37:32 +03:00
parent 5d617e41c7
commit 364f281384
@@ -16,6 +16,8 @@
package com.intellij.execution.process;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ReflectionUtil;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
@@ -60,9 +62,21 @@ public class WinProcessManager {
public static boolean kill(Process process, boolean tree) {
try {
int pid = getProcessPid(process);
String command = "taskkill /PID " + pid + (tree ? " /t" : "") + " /f";
LOG.debug(command);
Runtime.getRuntime().exec(command).waitFor();
String[] cmdArray = {"taskkill", "/f", "/pid", String.valueOf(pid), tree ? "/t" : ""};
if (LOG.isDebugEnabled()) {
LOG.debug(StringUtil.join(cmdArray, " "));
}
Process p = new ProcessBuilder(cmdArray).redirectErrorStream(true).start();
String output = FileUtil.loadTextAndClose(p.getInputStream());
int res = p.waitFor();
if (res != 0) {
LOG.warn(StringUtil.join(cmdArray, " ") + " failed: " + output);
return false;
}
else if (LOG.isDebugEnabled()) {
LOG.debug(output);
}
return true;
}
catch (Exception e) {