【发布时间】:2013-04-30 11:02:13
【问题描述】:
我正在尝试通过 jSch0.1.49 库连接在 unix 服务器上运行命令。我浏览过 jSch 甚至http://sourceforge.net/apps/mediawiki/jsch/index.php?title=Official_examples提供的示例
我能够从服务器读取响应并将其打印到控制台,但循环是 *never endin*g。我怀疑为什么 Channele 在读取完服务器的响应后没有关闭。
while (true) {
while (inputStream.available() > 0) {
int i = inputStream.read(buffer, 0, 1024);
if (i < 0) {
break;
}
System.out.print(new String(buffer, 0, i));//It is printing the response to console
}
System.out.println("done");// It is printing continuously infinite times
if (channel.isClosed()) {//It is never closed
System.out.println("exit-status: " + channel.getExitStatus());
break;
}
try{Thread.sleep(1000);}catch(Exception ee){}
}
【问题讨论】: