channel.setOutputStream(System.out, true); channel.setExtOutputStream(System.err, true); channel.setPty(true); channel.connect();
protected ChannelExec getChannelExec() throws JSchException { ChannelExec exec = (ChannelExec) session.openChannel(EXEC); if (context.isRequestPseudoTerminal()) { exec.setPty(true); } return exec; }
/** * Gets the channel with response. * * @param session * the session * @param command * the command * @return the channel with response * @throws JSchException * the j sch exception * @throws IOException * Signals that an I/O exception has occurred. */ public static Channel getChannelWithResponse(Session session, String command) throws JSchException, IOException { session.connect(); Channel channel = session.openChannel("exec"); if(command.contains("sudo")){ ((ChannelExec) channel).setPty(true); } ((ChannelExec) channel).setCommand(command); ((ChannelExec) channel).setErrStream(System.err); return channel; }
/** * Gets the channel with response. * * @param session * the session * @param command * the command * @return the channel with response * @throws JSchException * the j sch exception * @throws IOException * Signals that an I/O exception has occurred. */ public static Channel getChannelWithResponse(Session session, String command) throws JSchException, IOException { session.connect(); Channel channel = session.openChannel("exec"); if(command.contains("sudo")){ ((ChannelExec) channel).setPty(true); } ((ChannelExec) channel).setCommand(command); ((ChannelExec) channel).setErrStream(System.err); return channel; }
private ChannelExec createChannel(final PrintStream logger, final Session session) throws JSchException { final ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setOutputStream(logger, true); channel.setExtOutputStream(logger, true); channel.setInputStream(null); if (pty == null) { pty = Boolean.FALSE; } channel.setPty(pty); return channel; }
@Override public ChannelExec create() throws Exception { checkConnected(); String channel = "exec"; executor = (ChannelExec) sessionConnection.getSession().openChannel(channel); executor.setPty(true); executor.setCommand(command); inputStream = executor.getInputStream(); errStream = executor.getErrStream(); executor.connect(); return executor; }
@Override public ChannelExec create() throws Exception { checkConnected(); String channel = "exec"; executor = (ChannelExec) sessionConnection.getSession().openChannel(channel); executor.setPty(true); executor.setCommand(command); inputStream = executor.getInputStream(); errStream = executor.getErrStream(); executor.connect(); return executor; }
public ChannelReaderResponse executeResponsiveExecJsch(Session session, Command command){ ChannelReaderResponse channelReaderResponse = new ChannelReaderResponse(); ChannelExec channelExec = null; BufferedReader br = null; PrintStream ps = null; try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); br = new BufferedReader(new InputStreamReader( channelExec.getInputStream())); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } } channelReaderResponse.setChannel(channelExec); channelReaderResponse.setReader(br); return channelReaderResponse; }
public ChannelReaderResponse executeResponsiveExecJsch(Session session, Command command){ ChannelReaderResponse channelReaderResponse = new ChannelReaderResponse(); ChannelExec channelExec = null; BufferedReader br = null; PrintStream ps = null; try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); br = new BufferedReader(new InputStreamReader( channelExec.getInputStream())); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } } channelReaderResponse.setChannel(channelExec); channelReaderResponse.setReader(br); return channelReaderResponse; }
@Override public ChannelExec create() throws Exception { checkConnected(); String channel = "exec"; executor = (ChannelExec) sessionConnection.getSession().openChannel(channel); executor.setPty(true); executor.setCommand(command); inputStream = executor.getInputStream(); errStream = executor.getErrStream(); executor.connect(); return executor; }
public String executeResponsiveExecJsch(){ ChannelExec channelExec = null; PrintStream ps = null; InputStream in = null; String response = null; Session session = getSession(commandWritable, command); try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); in = channelExec.getInputStream(); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); response = getStringFromStream(in); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } closeChannel(channelExec); closeSession(session); } return response; }
public int executeCmd(String cmd, JobOutputProcessor sshOutputProcessor) throws JSchException, IOException { ChannelExec channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); channelExec.setCommand(cmd); channelExec.connect(); InputStream inputStream = channelExec.getInputStream(); Reader reader = new InputStreamReader(inputStream); char[] buf = new char[1024]; int numRead; // use while(true) to completely wait until closing channel while(true) { while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); if (sshOutputProcessor != null) { sshOutputProcessor.output(readData); } } if(channelExec.isClosed()) { break; } } int exitCode = channelExec.getExitStatus(); channelExec.disconnect(); return exitCode; }
public String executeResponsiveExecJsch(){ ChannelExec channelExec = null; PrintStream ps = null; InputStream in = null; String response = null; Session session = getSession(commandWritable, command); try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); in = channelExec.getInputStream(); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); response = getStringFromStream(in); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } closeChannel(channelExec); closeSession(session); } return response; }
public void executeExecJsch(){ performCommandCuration(command); ChannelExec channelExec = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); InputStream is = channelExec.getInputStream(); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); errorDebug = logJsch(channelExec, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Exec JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelExec.getExitStatus()+"]"); if(channelExec.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelExec); closeSession(session); } }
public void executeExecJsch(CommandWritable commandWritable, Command command){ performCommandCuration(command); ChannelExec channelExec = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelExec = (ChannelExec) session.openChannel("exec"); channelExec.setPty(true); InputStream is = channelExec.getInputStream(); channelExec.connect(); ps = new PrintStream(channelExec.getOutputStream(), true); ps.println(command.getCommandString()); errorDebug = logJsch(channelExec, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Exec JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelExec.getExitStatus()+"]"); if(channelExec.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelExec); closeSession(session); } }
aShell .setPty (true ); aShell .setCommand (sRealCmd);
aShell .setPty (true ); aShell .setCommand (sRealCmd);
public static Process start(SshRoot root, boolean tty, OutputStream out, String ... command) throws JSchException { TimedOutputStream dest; ChannelExec channel; dest = new TimedOutputStream(out); channel = root.createChannelExec(); // tty=true propagates ctrl-c to the remote host: // (unfortunately, this causes ssh servers to send cr/lf, and I didn't find // a way to stop this - I tried setPtyType and setTerminalMode) channel.setPty(tty); // TODO: http://tools.ietf.org/html/rfc4250 // TODO: channel.setTerminalMode(new byte[] { 70, 0, 0, 0, 0, /*71, 0, 0, 0, 0,*/ 0 }); channel.setCommand(Separator.SPACE.join(command)); channel.setInputStream(null); channel.setOutputStream(dest); channel.setExtOutputStream(dest); channel.connect(); return new Process(root, command, channel, dest); }
execChannel.setPty(true); // Allocate a Pseudo-Terminal. Thus it supports login sessions. (eg. /bin/bash -l)
public static Process start(SshRoot root, boolean tty, OutputStream out, String ... command) throws JSchException { TimedOutputStream dest; ChannelExec channel; dest = new TimedOutputStream(out); channel = root.createChannelExec(); // tty=true propagates ctrl-c to the remote host: // (unfortunately, this causes ssh servers to send cr/lf, and I didn't find // a way to stop this - I tried setPtyType and setTerminalMode) channel.setPty(tty); // TODO: http://tools.ietf.org/html/rfc4250 // TODO: channel.setTerminalMode(new byte[] { 70, 0, 0, 0, 0, /*71, 0, 0, 0, 0,*/ 0 }); channel.setCommand(Separator.SPACE.join(command)); channel.setInputStream(null); channel.setOutputStream(dest); channel.setExtOutputStream(dest); channel.connect(); return new Process(root, command, channel, dest); }