diff --git a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java index 1c0337379493..dc3245de185c 100644 --- a/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java +++ b/platform/platform-api/src/com/intellij/execution/process/CapturingProcessHandler.java @@ -67,7 +67,7 @@ public class CapturingProcessHandler extends OSProcessHandler { public ProcessOutput runProcess() { startNotify(); if (waitFor()) { - myOutput.setExitCode(getProcess().exitValue()); + setErrorCodeIfNotYetSet(); } else { LOG.info("runProcess: exit value unavailable"); @@ -75,6 +75,14 @@ public class CapturingProcessHandler extends OSProcessHandler { return myOutput; } + private void setErrorCodeIfNotYetSet() { + // if exit code was set on processTerminated, no need to rewrite it + // WinPtyProcess returns -2 if pty is already closed + if (myOutput.hasErrorExitCode()) { + myOutput.setExitCode(getProcess().exitValue()); + } + } + /** * Starts process with specified timeout * @@ -97,7 +105,7 @@ public class CapturingProcessHandler extends OSProcessHandler { else { startNotify(); if (waitFor(timeoutInMilliseconds)) { - myOutput.setExitCode(getProcess().exitValue()); + setErrorCodeIfNotYetSet(); } else { if (destroyOnTimeout) { @@ -156,7 +164,7 @@ public class CapturingProcessHandler extends OSProcessHandler { } if (setExitCode) { if (waitFor()) { - myOutput.setExitCode(getProcess().exitValue()); + setErrorCodeIfNotYetSet(); } else { LOG.info("runProcess: exit value unavailable");