Hi,
I have a trouble using (SSH)Exec problem.
It is that "channel object" sometimes fails to detect the close signal.
Can anyone help me?
While program does polling a remote SSH server by "ls" command,
"if(channel.isClosed())" sometimes doesn't change true forever!
According to my experience, it occurs after running some nights or
more than 1000 times loop.
For debug, I add below test message, then it appears.
It shows exit status code changed( from -1 to 0 ),
but channel hasn't closed.
if( !channel.isClosed() && channel.getExitStatus() == 0 ){
System.out.println("before close exit-status changed!" );
}
Q1. Is is a known problem?
Q2. How should I write program to recover this problem?
------ source code -------------------------------
while( true ){ // infinite loop
try{
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand( "ls" );
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){ // wait command end
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;
}
// for debug, if miss isClosed()
if( !channel.isClosed() && channel.getExitStatus() == 0 ){
System.out.println("before close exit-status changed!" );
}
try{
Thread.sleep(1000);
}catch(Exception ee){}
} // while( true ){ //wait command end
channel.disconnect();
} catch(Exception e){
System.out.println(e);
}
}// while( true ){ // infinite loop
------ source code -------------------------------
Best Regards,
----------------------------------
Yukimasa Matsuda
Quatre-i Science Co., Ltd.
e-mail: [email protected]
http://www.i4s.co.jp
----------------------------------
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users