channel.setOutputStream(System.out, true); channel.setExtOutputStream(System.err, true); channel.setPty(true);
@Override public void redirectStandardOutput(OutputStream output, boolean dontClose) { LOG.debug("Redirecting remote standard output: {}", command); channel.setOutputStream(output, dontClose); }
ChannelExec deployWarFile = (ChannelExec)session.openChannel("exec"); deployWarFile.setCommand("/path/to/count-the-bytes"); deployWarFile.setOutputStream(System.out); deployWarFile.setInputStream(new BufferedInputStream(new FileInputStream(warFile))); deployWarFile.connect();
private void checkForRosCore() throws JSchException, IOException { int pid = -1; ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand("ps aux | grep roscore | grep -v grep | awk '{ print $2 }'"); channel.setInputStream(null); channel.setOutputStream(System.out); BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream())); channel.connect(CONNECTION_TIMEOUT); String tmp = reader.readLine(); if (tmp != null) pid = Integer.parseInt(tmp); channel.disconnect(); if (pid < 0) { shellPrintStream.println("roscore &"); } }
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; }
public class sshConnect extends AsyncTask <String, Void, String>{ ByteArrayOutputStream Baos=new ByteArrayOutputStream(); ByteArrayInputStream Bais = new ByteArrayInputStream(new byte[1000]); @Override protected String doInBackground(String... data) { cSession jschses = new cSession(); Session ses =null; ses = jschses.Met1(); try { ses.connect(); ChannelExec channel = (ChannelExec)ses.openChannel("exec"); channel.setOutputStream(Baos); channel.setInputStream(Bais); //Run Command channel.setCommand("python ~/BBB_test/testconnect.py"); channel.connect(); try{Thread.sleep(3500);}catch (Exception ee){} channel.disconnect(); //session.disconnect(); }catch (Exception e){ System.out.println(e.getMessage()); } return Baos.toString(); }
channel.setCommand(GazeboProcessManagementCommandStrings.GET_SCS_PID); channel.setInputStream(null); channel.setOutputStream(System.out);
session.openChannel("exec"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); channelssh.setOutputStream(baos);
channel.setCommand(GazeboProcessManagementCommandStrings.GET_ROSLAUNCH_TASK); channel.setInputStream(null); channel.setOutputStream(System.out);
channel.setCommand(GazeboProcessManagementCommandStrings.GET_ROSLAUNCH_PID); channel.setInputStream(null); channel.setOutputStream(System.out);
@Override public int exec() throws IOException { try { final ChannelExec channel = ChannelExec.class.cast( this.session.openChannel("exec") ); channel.setErrStream(this.stderr, false); channel.setOutputStream(this.stdout, false); channel.setInputStream(this.stdin, false); channel.setCommand(this.command); channel.connect(); Logger.info(this, "$ %s", this.command); return this.exec(channel); } catch (final JSchException ex) { throw new IOException(ex); } finally { this.session.disconnect(); } }
public void sendCommandThroughExecChannel(LocalCloudMachines machine, String command) { try { ChannelExec channel = (ChannelExec) sessionForMachine(machine).openChannel("exec"); channel.setCommand(command); channel.setInputStream(null); channel.setOutputStream(System.out); } catch (JSchException e) { e.printStackTrace(); } }
@Override public int exec() throws IOException { try { final ChannelExec channel = ChannelExec.class.cast( this.session.openChannel("exec") ); channel.setErrStream(this.stderr, false); channel.setOutputStream(this.stdout, false); channel.setInputStream(this.stdin, false); channel.setCommand(this.command); channel.connect(); Logger.info(this, "$ %s", this.command); return this.exec(channel); } catch (final JSchException ex) { throw new IOException(ex); } finally { this.session.disconnect(); } }
public ChannelExecWrapper( Session session, String command, InputStream stdIn, OutputStream stdOut, OutputStream stdErr ) throws JSchException, IOException { this.command = command; this.channel = (ChannelExec) session.openChannel( "exec" ); if ( stdIn != null ) { this.passedInStdIn = stdIn; this.channel.setInputStream( stdIn ); } if ( stdOut != null ) { this.passedInStdOut = stdOut; this.channel.setOutputStream( stdOut ); } if ( stdErr != null ) { this.passedInStdErr = stdErr; this.channel.setErrStream( stdErr ); } this.channel.setCommand( command ); this.channel.connect(); }
public ChannelExecWrapper( Session session, String command, InputStream stdIn, OutputStream stdOut, OutputStream stdErr ) throws JSchException, IOException { this.command = command; this.channel = (ChannelExec) session.openChannel( "exec" ); if ( stdIn != null ) { this.passedInStdIn = stdIn; this.channel.setInputStream( stdIn ); } if ( stdOut != null ) { this.passedInStdOut = stdOut; this.channel.setOutputStream( stdOut ); } if ( stdErr != null ) { this.passedInStdErr = stdErr; this.channel.setErrStream( stdErr ); } this.channel.setCommand( command ); this.channel.connect(); }
private int execute0(Session session, List<String> commandLineTokens, Map<String, String> environmentVariables, OutputStream output) throws JSchException, InterruptedException { ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(buildCommand(commandLineTokens, environmentVariables)); channel.setInputStream(new ByteArrayInputStream(new byte[0]), true); channel.setOutputStream(output, true); channel.setErrStream(output, true); YSLOG.info("I00003", user, host, port, privateKey, commandLineTokens.get(0)); long channelStart = System.currentTimeMillis(); channel.connect((int) TimeUnit.SECONDS.toMillis(60)); long channelEnd = System.currentTimeMillis(); YSLOG.info("I00004", user, host, port, privateKey, commandLineTokens.get(0), channelEnd - channelStart); int exitStatus; try { while (true) { if (channel.isClosed()) { break; } Thread.sleep(100); } exitStatus = channel.getExitStatus(); } finally { channel.disconnect(); } YSLOG.info("I00005", user, host, port, privateKey, commandLineTokens.get(0), exitStatus); return exitStatus; }
@Override protected void submit_generate_job_inner() throws InvocationException { tags.put("uniqueID", "" + getSubmissionID()); String command = usecase.getCommand(); for (String cur : tags.keySet()) { command = command.replaceAll("\\Q%%" + cur + "%%\\E", tags.get(cur)); } String fullCommand = "cd " + workerNode.getDirectory() + tmpname; for (String preceding : precedingCommands) { fullCommand += " && " + preceding; } fullCommand += " && " + command; logger.info("Full command is " + fullCommand); try { running = SshPool.openExecChannel(workerNode, askUserForPw); running.setCommand(fullCommand); running.setOutputStream(stdout_buf); running.setErrStream(stderr_buf); if (stdInputStream != null) { running.setInputStream(stdInputStream); } running.connect(); } catch (JSchException e) { throw new InvocationException(e); } }
public void killSim(LocalCloudMachines gazeboMachine) { if (isMachineReachable(gazeboMachine)) { if (isMachineRunningSim(gazeboMachine)) { try { int PID = getRosSimPID(gazeboMachine); ChannelExec channel = (ChannelExec) sessions.get(gazeboMachine).openChannel("exec"); channel.setCommand("kill -2 " + PID); channel.setInputStream(null); channel.setOutputStream(System.out); channel.connect(CONNECTION_TIMEOUT); channel.disconnect(); updateRosSimPID(gazeboMachine); updateRosSimTaskname(gazeboMachine); } catch (JSchException e) { e.printStackTrace(); } } else { System.err.println("No sim running on " + gazeboMachine); } } }
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); }
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); }