【问题标题】:jcabi ssh redirect output to null or filejcabi ssh 将输出重定向到 null 或文件
【发布时间】:2016-07-05 14:22:55
【问题描述】:

我正在编写一个小应用程序来通过 SSH 连接到服务器列表并执行一些命令。我正在使用jcabi-ssh。当我运行程序时,jcabi-ssh 会输出到控制台,其中包含以下行:

[main] WARN com.jcabi.ssh.SSH - Permanently added '192.168.4.2' (RSA) to the list of known hosts.
[main] INFO com.jcabi.ssh.Execution$Default - $ ping -c 1 google.com

我的代码sn-p如下:

Shell shell = new SSHByPassword(targetServer.toString(), Integer.parseInt(port), username.toString(), password.toString());
exitCode=shell.exec("ping -c 1 google.com",stdin,stdout,stderr);

我想隐藏控制台输出或将其重定向到文件。我查看了source,但似乎我无法通过方法调用来做到这一点。有没有办法做我想做的事?

谢谢!

【问题讨论】:

    标签: java ssh jcabi


    【解决方案1】:

    您应该只禁止登录您的应用程序。 jcabi-ssh 正在使用 slf4j。您在日志中看到的内容是通过 slf4j 到(很可能)log4j。确保com.jcabi.ssh 的日志级别设置为ERROR,这样就可以了。

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 1970-01-01
      • 2011-02-06
      • 1970-01-01
      • 2012-01-04
      • 2016-08-09
      • 2013-10-11
      • 2023-03-19
      • 2014-03-31
      相关资源
      最近更新 更多