gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:31 24 4
gpt4 key购买 nike

我正在编写一个小应用程序,通过 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但似乎我无法通过方法调用来做到这一点。有办法做我想做的事吗?

谢谢!

最佳答案

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

关于java - jcabi ssh 将输出重定向到 null 或文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38205920/

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