我使用SSHJ打开SSH会话并执行命令。 我遇到了一个问题,我无法获取命令的输出。谁能帮我吗?
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(
new HostKeyVerifier() {
public boolean verify(String arg0, int arg1, PublicKey arg2) {
return true;
}
}
);
ssh.connect(this.hostName, this.port);
ssh.authPassword("santera", "santera1");
//final Console con = System.console();
Session session = ssh.startSession();
session.allocateDefaultPTY();
Shell shell = session.startShell();
Expect expect = new ExpectBuilder()
.withOutput(shell.getOutputStream())
.withInputs(shell.getInputStream(), shell.getErrorStream())
.withEchoInput(System.out)
.withEchoOutput(System.err)
.withExceptionOnFailure()
.build();
expect.sendLine("script test.txt");
expect.expect(contains("%"));
expect.sendLine("ls -l"); // ls -l is a command
expect.expect(contains("%")); // % is a prompt
我想将命令的输出从'command'转换为'prompt'。