try (ClientChannel channel = session.createExecChannel(command.toString())) { channel.setIn(new NoCloseInputStream(System.in)); channel.setOut(new NoCloseOutputStream(System.out));
protected ChannelExec openCommandChannel(ClientSession session, String cmd) throws IOException { long waitTimeout = session.getLongProperty(SCP_EXEC_CHANNEL_OPEN_TIMEOUT, DEFAULT_EXEC_CHANNEL_OPEN_TIMEOUT); ChannelExec channel = session.createExecChannel(cmd); long startTime = System.nanoTime(); try { channel.open().verify(waitTimeout); long endTime = System.nanoTime(); long nanosWait = endTime - startTime; if (log.isTraceEnabled()) { log.trace("openCommandChannel(" + session + ")[" + cmd + "]" + " completed after " + nanosWait + " nanos out of " + TimeUnit.MILLISECONDS.toNanos(waitTimeout)); } return channel; } catch (IOException | RuntimeException e) { long endTime = System.nanoTime(); long nanosWait = endTime - startTime; if (log.isTraceEnabled()) { log.trace("openCommandChannel(" + session + ")[" + cmd + "]" + " failed (" + e.getClass().getSimpleName() + ")" + " to complete after " + nanosWait + " nanos out of " + TimeUnit.MILLISECONDS.toNanos(waitTimeout) + ": " + e.getMessage()); } channel.close(false); throw e; } }
@Override public Process exec(String commandName, int timeout) throws IOException { @SuppressWarnings("resource") ChannelExec exec = session.createExecChannel(commandName); long timeoutMillis = TimeUnit.SECONDS.toMillis(timeout); try { if (timeout <= 0) { exec.open().verify(); } else { long start = System.nanoTime(); exec.open().verify(timeoutMillis); timeoutMillis -= TimeUnit.NANOSECONDS .toMillis(System.nanoTime() - start); } } catch (IOException e) { exec.close(true); throw e; } catch (RuntimeException e) { exec.close(true); throw e; } if (timeout > 0 && timeoutMillis <= 0) { // We have used up the whole timeout for opening the channel exec.close(true); throw new InterruptedIOException( format(SshdText.get().sshCommandTimeout, commandName, Integer.valueOf(timeout))); } return new SshdExecProcess(exec, commandName, timeoutMillis); }
final ProgressOutputStream iout = new ProgressOutputStream(out); final ProgressOutputStream ierr = new ProgressOutputStream(err)) { channel = session.createExecChannel(command); channel.setIn(iin); channel.setOut(iout);
ClientChannel channel = createExecChannel(command)) { channel.setOut(channelOut); channel.setErr(channelErr);
ClientChannel channel = createExecChannel(command)) { channel.setOut(channelOut); channel.setErr(channelErr);
.build()) { if (config.getCommand().length() > 0) { ChannelExec channel = session.createExecChannel(config.getCommand() + "\n"); channel.setIn(new ByteArrayInputStream(new byte[0])); new Thread() {
.build()) { if (config.getCommand().length() > 0) { ChannelExec channel = session.createExecChannel(config.getCommand() + "\n"); channel.setIn(new ByteArrayInputStream(new byte[0])); new Thread() {
ChannelExec shell = s.createExecChannel("normal");
ChannelExec shell = s.createExecChannel("normal");
ChannelExec shell = s.createExecChannel("normal");
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { shell.addChannelListener(new ChannelListener() { @Override
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { shell.addChannelListener(new ChannelListener() { @Override
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { shell.addChannelListener(new ChannelListener() { @Override
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { for (Map.Entry<String, String> ee : expected.entrySet()) { shell.setEnv(ee.getKey(), ee.getValue());
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { for (Map.Entry<String, String> ee : expected.entrySet()) { shell.setEnv(ee.getKey(), ee.getValue());
ChannelExec shell = s.createExecChannel(getCurrentTestName())) { for (Map.Entry<String, String> ee : expected.entrySet()) { shell.setEnv(ee.getKey(), ee.getValue());