channel.setInputStream(null);
((ChannelExec) channel).setCommand(command); channel.setInputStream(null);
@Signature public void setInputStream(Environment env, @Nullable Stream stream, boolean dontClose) { getWrappedObject().setInputStream(stream == null ? null : Stream.getInputStream(env, stream), dontClose); }
((ChannelExec) channel).setCommand(command); channel.setInputStream(null);
((ChannelExec) channel).setCommand(command); channel.setInputStream(null);
public CommandChannel build() { try { Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command); channel.setInputStream(in); return new CommandChannelSuccess(ssh, channel); } catch (JSchException e) { return new CommandChannelFailed(ssh, e); } }
channel.setInputStream(null); BufferedReader r = new BufferedReader(new InputStreamReader(((ChannelExec) channel).getErrStream()));
Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command1); channel.setInputStream(null); ((ChannelExec) channel).setErrStream(System.err); channel.connect();
Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command2); channel.setInputStream(null); ((ChannelExec) channel).setErrStream(System.err); channel.connect();
@Override public final Collection<Metric> gatherMetrics(final ICommandLine cl) throws MetricGatheringException { List<Metric> metrics = new ArrayList<Metric>(); Session session = null; try { session = SshUtils.getSession(cl); Channel channel = session.openChannel("shell"); channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(); metrics.add(new Metric("connected", "", new BigDecimal(1), null, null)); channel.disconnect(); session.disconnect(); } catch (Exception e) { String message = e.getMessage(); metrics.add(new Metric("connected", message, new BigDecimal(0), null, null)); LOG.debug(getContext(), message, e); } return metrics; }
protected void execute(Channel channel, String pw) throws JSchException, IOException { channel.setInputStream(null); InputStream in=channel.getInputStream(); OutputStream out=channel.getOutputStream(); ((ChannelExec)channel).setErrStream(System.err); channel.connect(); if(!pw.isEmpty()){ out.write((pw+"\n").getBytes()); out.flush(); } byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0)break; System.out.print(new String(tmp, 0, i)); } if(channel.isClosed()){ System.out.println("exit-status: "+channel.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} } channel.disconnect(); } }
channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(cmd); channel.setInputStream(System.in); InputStream in = channel.getInputStream(); channel.connect();
channel.setInputStream(in); channel.connect(3000);
channel.setInputStream(null);
channel.setInputStream(null);
((ChannelExec) channel).setCommand(command); channel.setInputStream(null); ((ChannelExec) channel).setErrStream(System.err);
((ChannelShell) channel).setAgentForwarding(agentForwarding); InputStream in = new ByteArrayInputStream(command.getBytes(characterSet)); channel.setInputStream(in); OutputStream out = new ByteArrayOutputStream(); channel.setOutputStream(out);
((ChannelShell) channel).setAgentForwarding(agentForwarding); InputStream in = new ByteArrayInputStream(command.getBytes(characterSet)); channel.setInputStream(in); OutputStream out = new ByteArrayOutputStream(); channel.setOutputStream(out);
channel.setInputStream(null); ((ChannelExec) channel).setErrStream(commandOutput.getStandardError()); try {
/** * 返回执行命令的内容 * @param command * @return String */ public String execStr(String command) { Channel channel=getChannel(); String res=""; try { ((ChannelExec)channel).setCommand(command); InputStream in=channel.getInputStream(); channel.setInputStream(null); ((ChannelExec)channel).setErrStream(System.err); channel.connect(); res=FileUtil.readInputStreamToString(in, "UTF-8"); in=null; // log.info("命令:"+command+"执行完毕\n"); // log.info("命令执行结果为:\n"+res); } catch (IOException e) { log.error("命令:"+command+"执行异常"); log.error(e.getMessage()); } catch (JSchException e) { log.error("命令:"+command+"执行异常"); log.error(e.getMessage()); } return res; }