【问题标题】:Java - JSch - Getting exit status 123. What does it mean?Java - JSch - 获取退出状态 123. 这是什么意思?
【发布时间】:2018-04-11 09:32:08
【问题描述】:

运行命令从远程服务器上的文件中检索数据(代码如下)。 在关闭频道时,有时会收到退出代码 123。

发现于https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

ERROR_INVALID_NAME 123 (0x7B) 文件名、目录名或卷 标签语法不正确。

但我不确定它是相同的错误代码含义。 请指教

代码:

JSch jsch = new JSch();
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session = jsch.getSession(BillingUser, BillingHost, 22);
session.setPassword(BillingPassword);
session.setConfig(config);     
session.connect();                       
channel = session.openChannel("exec");          
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
(ChannelExec) channel).setErrStream(System.out);
InputStream inputStream = channel.getInputStream();
InputStream errStream = channel.getExtInputStream();
channel.connect();
if (inputStream.available() > 0) {
    //saving output here
}
inputStream.close();
errStream.close();
if (channel.isClosed()) {
    if (channel.getExitStatus() != 0){
        //printing here exitStatus value
    }
}

连接到 Linux。运行命令如下:

find filesPath -type f -name "meAutomation,meAutomation*"| xargs egrep -r -i "20171031(04|03).*,meAutomation,meAutomation,.*,mEnterprise.*"

【问题讨论】:

    标签: java shell ssh jsch exit-code


    【解决方案1】:

    退出代码是系统特定的。

    您可能正在连接到 *nix 系统。因此,您可能想阅读
    Got exit code 123 in find + xargs grep 的答案。

    123 表示“任何以非零状态退出的调用”。


    强制警告:不要使用StrictHostKeyChecking=no 盲目接受所有主机密钥。那是一个安全漏洞。您将失去对MITM attacks 的保护。有关正确(且安全)的方法,请参阅:How to resolve Java UnknownHostKey, while using JSch SFTP library?

    【讨论】:

    • 谢谢,我相信是它。只需了解我的命令中的哪些内容可能导致非零状态:) 恐怕这就是答案:如果有返回零匹配的 grep 调用,退出代码仍将是 123
    猜你喜欢
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2013-06-15
    • 2014-02-12
    • 2011-08-19
    相关资源
    最近更新 更多