From 9db2ce29412f287274b99e5913eedc9a98f09f6a Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 18 May 2016 12:51:00 +0300 Subject: [PATCH] IDEA-156065 WinPty process does not kill agent on end - fixed incorrect exit code after winptyprocess termination --- .../execution/process/CapturingProcessHandler.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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");