问题描述
我正在将Expectit库与sshj一起使用,并且无法向会话发送Expect命令。一切似乎都停止在第二个Expect命令上:
client = new SSHClient();
client.addHostkeyverifier(new Promiscuousverifier());
client.connect("xxx",xx);
client.authPassword("xxx","xxx");
session = client.startSession();
session.allocateDefaultPTY()
shell = session.startShell();
wholeBuffer = new StringBuilder();
expectBuilder = new ExpectBuilder()
.withOutput(shell.getoutputStream())
.withInputs(shell.getInputStream(),shell.getErrorStream())
.withEchoOutput(wholeBuffer)
.withEchoInput(wholeBuffer)
.withExceptionOnFailure()
.build();
expectBuilder.expect(contains(" >"))
expectBuilder.sendLine("set default sys\$system")
expectBuilder.expect(contains(" >")) // <- This is where it times out
println wholeBuffer
client.disconnect()
session.close();
expectBuilder.close();
我能够获得包括“设置默认sys $ system”在内的初始登录消息的输出,但此后它将停止。我尝试使用PTY设置无济于事,还尝试了Jsch库,但得到了相同的结果。我猜想这与会话持久性有关,我无法弄清。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)