【发布时间】:2014-03-14 18:38:10
【问题描述】:
我正在使用 Ganymed-ssh 远程提取日志详细信息。下面是我的代码。有时 stdout 返回的数据很大,因此返回需要更多时间。如果标准输出在 1 分钟内没有返回,我想关闭会话。如何设置会话超时自动关闭标准输出超过 1 分钟?
Connection conn = new Connection(hostname);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
Session session = conn.openSession();
session.execCommand("grep traceid trace.log");
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
System.out.println("ExitCode: " + session.getExitStatus());
session.close();
conn.close();
【问题讨论】: