IDEA-156065 WinPty process does not kill agent on end - fixed incorrect exit code after winptyprocess termination

This commit is contained in:
Egor.Ushakov
2016-05-18 12:52:02 +03:00
parent 1d6688473d
commit 9db2ce2941
@@ -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");