ChannelShell channel = openShellChannel(); OutputStream outputStream = channel.getOutputStream(); PrintStream commander = new PrintStream(outputStream, true); // Print logs channel.setOutputStream(System.out, true); // exec the command commander.println(command);
private void initShellConnection() throws JSchException, IOException { jsch = new JSch(); config = new Properties(); config.put("StrictHostKeyChecking", "no"); session = jsch.getSession("unknownid", "127.0.0.1", 22); session.setConfig(config); session.setPassword("unknownpw"); session.connect(CONNECTION_TIMEOUT); ChannelShell channel = (ChannelShell) session.openChannel("shell"); shellPrintStream = new PrintStream(channel.getOutputStream(), true); channel.setOutputStream(null); channel.setInputStream(null); channel.connect(CONNECTION_TIMEOUT); channel.setOutputStream(System.out); checkForRosCore(); }
ChannelShell shellChannel = (ChannelShell) session.openChannel("shell"); shellChannel.setOutputStream(outputStream, true); InputStream in = new PipedInputStream(); PipedOutputStream pin = new PipedOutputStream((PipedInputStream) in); shellChannel.setInputStream(in); shellChannel.connect(); pin.write("ls \r").getBytes());
private void setupSession(LocalCloudMachines machine, ImmutablePair<String, String> authPair) throws JSchException { Session session; session = jsch.getSession(authPair.getLeft(), machine.getIp(), 22); session.setConfig(config); session.setPassword(authPair.getRight()); session.connect(30000); sessions.put(machine, session); try { ChannelShell channel = (ChannelShell) sessions.get(machine).openChannel("shell"); shellPrintStreams.put(channel, new PrintStream(channel.getOutputStream(), true)); channel.setOutputStream(null); channel.setInputStream(null); channel.connect(CONNECTION_TIMEOUT); shellChannels.put(session, channel); channel.setOutputStream(System.out); } catch (IOException e) { e.printStackTrace(); } }
consoleInput = new PipedOutputStream(inputStream); consoleOutput = inputStream; channel.setOutputStream(consoleInput); channel.setInputStream(consoleOutput);
session = createSession(output); channel = (ChannelShell) session.openChannel("shell"); channel.setOutputStream(output, true); channel.setExtOutputStream(output, true); channel.setPty(Boolean.FALSE);
shell.setOutputStream(stream);