if (useSystemIn) {
istream = KeepAliveInputStream.wrapSystemIn();
}
try {
final ChannelExec channel;
session.setTimeout((int) maxwait);
/* execute the command */
channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(cmd);
channel.setOutputStream(tee);
channel.setExtOutputStream(tee);
channel.setErrStream(teeErr);
if (istream != null) {
channel.setInputStream(istream);
}
channel.setPty(usePty);
channel.connect();
// wait for it to finish
thread =
new Thread() {
public void run() {
while (!channel.isClosed()) {
if (thread == null) {
return;
}
try {
sleep(RETRY_INTERVAL);
} catch (Exception e) {
// ignored
}
}
}
};
thread.start();
thread.join(maxwait);
if (thread.isAlive()) {
// ran out of time
thread = null;
if (getFailonerror()) {
throw new BuildException(TIMEOUT_MESSAGE);
} else {
log(TIMEOUT_MESSAGE, Project.MSG_ERR);
}
} else {
// stdout to outputFile
if (outputFile != null) {
writeToFile(out.toString(), append, outputFile);
}
// set errorProperty
if (errorProperty != null) {
getProject().setNewProperty(errorProperty, errout.toString());
}
// stderr to errorFile
if (errorFile != null) {
writeToFile(errout.toString(), appenderr, errorFile);
}
// this is the wrong test if the remote OS is OpenVMS,
// but there doesn't seem to be a way to detect it.
int ec = channel.getExitStatus();
// set resultproperty
if (resultProperty != null) {
getProject().setNewProperty(resultProperty, Integer.toString(ec));
}
if (ec != 0) {