((ChannelExec) channel).setErrStream(System.err);
@Signature public void setErrorStream(Environment env, @Nullable Stream stream, boolean dontClose) { getWrappedObject().setErrStream(stream == null ? null : Stream.getOutputStream(env, stream), dontClose); } }
/** * * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#executeCommand(java.lang.String, java.lang.StringBuilder) } */ private int executeCommand( String command, StringBuilder output ) throws JSchException, IOException { this.ensureSession(); ChannelExec channel = (ChannelExec) this.session.openChannel( "exec" ); channel.setCommand( command ); channel.setInputStream( (InputStream) null ); InputStreamReader stream = new InputStreamReader( channel.getInputStream() ); channel.setErrStream( System.err, true ); channel.connect(); char[] buffer = new char[128]; int read; while ( ( read = stream.read( buffer, 0, buffer.length ) ) >= 0 ) { output.append( buffer, 0, read ); } stream.close(); while ( !channel.isClosed() ) { try { Thread.sleep( 100L ); } catch ( Exception exc ) { log.logMinimal( "Warning: Error session closing. " + exc.getMessage() ); } } channel.disconnect(); return channel.getExitStatus(); }
((ChannelExec) channel).setErrStream(System.err);
channel.setErrStream(errStream); InputStream in = null; try {
channel.setErrStream(errStream); InputStream in = null; try {
channel.setErrStream(outputStreamStdErr);
((ChannelExec) channel).setErrStream(System.err);
ChannelExec channelExec = (ChannelExec) channel; channelExec.setCommand(cmd); channelExec.setErrStream(System.err); channelExec.connect(); <-- Additional line
/** * 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; }
@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(); } }
@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(); } }
//Start EXEC ChannelExec ce = (ChannelExec) session.openChannel("exec"); ce.setCommand("screen -S " + name + " -X stuff 'quit\n'"); ce.setInputStream(null); ce.setErrStream(System.err); InputStream in=ce.getInputStream(); ce.connect(); 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(ce.isClosed()){ if(in.available()>0) continue; //System.out.println("exit-status: "+ce.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} } ce.disconnect(); //STOP EXEC
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(); }
public void updateInterval(Session s, String filename) { String checkfortimeupdate = "fgrep '-send' \"public_html/final/" + filename + "\""; ChannelExec channel = (ChannelExec)session.openChannel("exec"); channel.setCommand(checkfortimeupdate); channel.setInputStream(null); channel.setErrStream(System.err); BufferedReader in = new BufferedReader(new InputStreamReader(channel.getInputStream(), encoding)); channel.connect(); eatOutput(in); if (channel.isClosed()) { System.out.println("UpdateInterval Closed exit-status: " + channel.getExitStatus()); break; } channel.disconnect(); }
@Override public ExecChannel create() throws Exception { this.sessionConnection = acquire(SessionConnection.builder().from(JschSshClient.this.sessionConnection) .sessionTimeout(0).build()); String channel = "exec"; executor = (ChannelExec) sessionConnection.openChannel(channel); executor.setCommand(command); executor.setErrStream(new ByteArrayOutputStream()); InputStream inputStream = executor.getInputStream(); InputStream errStream = executor.getErrStream(); OutputStream outStream = executor.getOutputStream(); executor.connect(); return new ExecChannel(outStream, inputStream, errStream, new Supplier<Integer>() { @Override public Integer get() { int exitStatus = executor.getExitStatus(); return exitStatus != -1 ? exitStatus : null; } }, new Closeable() { @Override public void close() throws IOException { clear(); } }); }
@Override public ExecChannel create() throws Exception { this.sessionConnection = acquire(SessionConnection.builder().from(JschSshClient.this.sessionConnection) .sessionTimeout(0).build()); String channel = "exec"; executor = (ChannelExec) sessionConnection.openChannel(channel); executor.setCommand(command); executor.setErrStream(new ByteArrayOutputStream()); InputStream inputStream = executor.getInputStream(); InputStream errStream = executor.getErrStream(); OutputStream outStream = executor.getOutputStream(); executor.connect(); return new ExecChannel(outStream, inputStream, errStream, new Supplier<Integer>() { @Override public Integer get() { int exitStatus = executor.getExitStatus(); return exitStatus != -1 ? exitStatus : null; } }, new Closeable() { @Override public void close() throws IOException { clear(); } }); }
((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); try { channel.connect();