use of org.eclipse.che.api.core.util.ListLineConsumer in project che by eclipse.
the class JschSshClient method execAndGetOutput.
private String execAndGetOutput(String command) throws JSchException, MachineException, IOException {
ChannelExec exec = (ChannelExec) session.openChannel("exec");
exec.setCommand(command);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
InputStream erStream = exec.getErrStream()) {
exec.connect(connectionTimeout);
ListLineConsumer listLineConsumer = new ListLineConsumer();
String line;
while ((line = reader.readLine()) != null) {
listLineConsumer.writeLine(line);
}
// read stream to wait until command finishes its work
IoUtil.readStream(erStream);
if (exec.getExitStatus() != 0) {
throw new MachineException(format("Error code: %s. Error: %s", exec.getExitStatus(), IoUtil.readAndCloseQuietly(exec.getErrStream())));
}
return listLineConsumer.getText();
} finally {
exec.disconnect();
}
}
use of org.eclipse.che.api.core.util.ListLineConsumer in project che by eclipse.
the class CommandExistsAgentChecker method isLaunched.
@Override
public boolean isLaunched(Agent agent, InstanceProcess process, Instance machine) throws MachineException {
Command command = new CommandImpl(format("Wait for %s, try %d", agent.getId(), ++counter), checkingCommand, "test");
try (ListLineConsumer lineConsumer = new ListLineConsumer()) {
InstanceProcess waitProcess = machine.createProcess(command, null);
waitProcess.start(lineConsumer);
return lineConsumer.getText().endsWith("[STDOUT] 0");
} catch (ConflictException e) {
throw new MachineException(e.getServiceError());
}
}
use of org.eclipse.che.api.core.util.ListLineConsumer in project che by eclipse.
the class ProcessIsLaunchedChecker method isLaunched.
@Override
public boolean isLaunched(Agent agent, InstanceProcess process, Instance machine) throws MachineException {
Command command = new CommandImpl(format("Wait for %s, try %d", agent.getId(), ++counter), format(CHECK_COMMAND, processNameToWait), "test");
try (ListLineConsumer lineConsumer = new ListLineConsumer()) {
InstanceProcess waitProcess = machine.createProcess(command, null);
waitProcess.start(lineConsumer);
return lineConsumer.getText().endsWith("[STDOUT] 0");
} catch (ConflictException e) {
throw new MachineException(e.getServiceError());
}
}
Aggregations