【问题标题】:ExpectIt: Suppress console echoExpectIt:抑制控制台回声
【发布时间】:2015-10-07 07:03:27
【问题描述】:

参考: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 容器(网络环境)中运行。

【问题讨论】:

    标签: java tomcat7 expectit


    【解决方案1】:

    您可以通过在会话开始时发送stty -echo 命令来禁用命令回显。看看this 的例子。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2011-02-08
      • 2013-03-16
      相关资源
      最近更新 更多