public Channel sessionConnectGenerateChannel ( Session session ) throws JSchException { // set timeout session . connect ( sshMeta . getSshConnectionTimeoutMillis ( ) ) ; ChannelExec channel = ( ChannelExec ) session . openChannel ( "exec" ) ; channel . setCommand ( sshMeta . getCommandLine ( ) ) ; // if run as super user, assuming the input stream expecting a password if ( sshMeta . isRunAsSuperUser ( ) ) { try { channel . setInputStream ( null , true ) ; OutputStream out = channel . getOutputStream ( ) ; channel . setOutputStream ( System . out , true ) ; channel . setExtOutputStream ( System . err , true ) ; channel . setPty ( true ) ; channel . connect ( ) ; out . write ( ( sshMeta . getPassword ( ) + "\n" ) . getBytes ( ) ) ; out . flush ( ) ; } catch ( IOException e ) { logger . error ( "error in sessionConnectGenerateChannel for super user" , e ) ; } } else { channel . setInputStream ( null ) ; channel . connect ( ) ; } return channel ; }
Session connect generate channel .