jcabi ssh将输出重定向到null或文件

时间:2016-07-05 14:22:56

标签: java ssh jcabi

我正在编写一个小应用程序,通过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

我的代码段如下:

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但似乎无法通过方法调用来完成它。有办法做我想做的事吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

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