gpt4 book ai didi

java - ExpectIt:抑制控制台回声

转载 作者:行者123 更新时间:2023-11-30 08:03:46 25 4
gpt4 key购买 nike

引用:ExpectIt : Trouble implementing a sudo -i

如何避免将 Expectit 的所有输出回显到我的 java 控制台?

这就是我开始 SSH 的方式:

public void connect( String host, String user, String password ) throws Exception {
this.host = host;
this.user = user;
this.password = password;
ssh = new SSHClient();
ssh.addHostKeyVerifier( new PromiscuousVerifier() );
ssh.connect(host, port);
ssh.authPassword(user, password);
session = ssh.startSession();

session.allocateDefaultPTY();
shell = session.startShell();

expect = new ExpectBuilder()
.withOutput(shell.getOutputStream())
.withInputs(shell.getInputStream(), shell.getErrorStream())
.withInputFilters(removeColors(), removeNonPrintable())
.withExceptionOnFailure()
.withTimeout(30, TimeUnit.SECONDS)
.build();

String result = expect.expect( Matchers.contains( PROMPT ) ).getInput();
consoleOut.add( result );

}

现在,从 Expect 获取的所有结果都将回显到控制台。我可以获取“结果”字符串,但它也会发送到 tomcat 控制台(我确定我不会将其发送到)。

expect.sendLine( command );
String result = expect.expect( Matchers.contains( PROMPT ) ).getInput();

我正在 Tomcat 容器(Web 环境)中运行。

enter image description here

最佳答案

您可以通过在 session 开始时发送 stty -echo 命令来禁用命令 echo。看看this示例。

我建议将问题发布到 ExpectIt user group而不是在 Stackoverflow 上,因为目前只有少数人在使用这个库。

关于java - ExpectIt:抑制控制台回声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31477843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com