Java SSH Expect操作仅在第一次运行时有效
我正在将expectit库与sshj一起使用,并且无法将expectit命令发送到会话。在第二个expect命令下,一切似乎都停止了:Java SSH Expect操作仅在第一次运行时有效,java,groovy,ssh,sshj,expectit,Java,Groovy,Ssh,Sshj,Expectit,我正在将expectit库与sshj一起使用,并且无法将expectit命令发送到会话。在第二个expect命令下,一切似乎都停止了: client = new SSHClient(); client.addHostKeyVerifier(new PromiscuousVerifier()); client.connect("xxx", xx); client.authPassword("xxx", "xxx"); session =
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库,但得到了相同的结果。我猜这与会话持久性有关,但我无法理解