close process's input stream after process termination

This commit is contained in:
Sergey Simonchik
2013-11-29 19:43:44 +04:00
parent 77e0f1a978
commit e962648fed
@@ -18,9 +18,11 @@ package com.intellij.execution.process;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.KillableProcess;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.charset.Charset;
/**
@@ -32,6 +34,8 @@ import java.nio.charset.Charset;
* P.S: probably OSProcessHandler is better place for this feature but it can affect other run configurations and should be tested
*/
public class KillableColoredProcessHandler extends ColoredProcessHandler implements KillableProcess {
private static final Logger LOG = Logger.getInstance(KillableColoredProcessHandler .class);
private boolean myShouldKillProcessSoftly = true;
public KillableColoredProcessHandler(GeneralCommandLine commandLine) throws ExecutionException {
@@ -73,6 +77,31 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme
return false;
}
@Override
protected void destroyProcessImpl() {
// call super.closeStreams() after process termination, because
// otherwise process's output stream can also be closed for no reason
try {
myProcess.getOutputStream().flush();
}
catch (IOException e) {
LOG.warn(e);
}
finally {
doDestroyProcess();
}
}
@Override
protected void notifyProcessTerminated(int exitCode) {
try {
super.closeStreams();
}
finally {
super.notifyProcessTerminated(exitCode);
}
}
@Override
protected void doDestroyProcess() {
boolean gracefulTerminationAttempted = false;