Hi,

I am having issue while trying to execute certain commands.Below is the code

I am creating session in object and pass it along with the command

--------------------------------------------------------------------------------------
private void executeCommand(Session session, String CMD) {
logInfo("Inside executeCommand method. CMD is :\n" +CMD);
try {
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(CMD);
            channel.setInputStream(null);
       ((ChannelExec)channel).setErrStream(System.err);
       InputStream in=channel.getInputStream();
       channel.connect();
       byte[] tmp=new byte[1024];
       while(true){
         while(in.available()>0){
           int i=in.read(tmp, 0, 1024);
                logInfo("Inside in.avilable()>0 while loop...");
                System.out.println("Inside in.avilable()>0 while loop...");
           if(i<0)break;
           logInfo(new String(tmp, 0, i));
         }

         if(channel.isClosed() || in.available() < 0){
           logInfo("exit-status: "+channel.getExitStatus());
           break;
         }
         try{
         Thread.sleep(1000);
         }catch(Exception e){
       LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
     System.exit(INIT_ERROR);
         }
              System.out.println("Inside while true loop...");
       }
       channel.disconnect();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
System.exit(INIT_ERROR);
}
}
-------------------------------------------------------------------------

Please help !!
-- 



*Thanks and Regards,Abhimanu Handoo*
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to