繁体   English   中英

Linux shell 脚本的退出状态 -1

[英]Exit status -1 from a Linux shell script

I have some Unix shell scripts in one of our servers and I have written a Java program using Spring Boot which is deployed in another application server.From my Spring Boot application, I am remotely executing the shell script at the other server. 我的程序如下:

public int execute(String scriptName, String environemntVariable,
            String serverIp, String username, String password) throws Exception {
        Session session = null;
        ChannelExec channelExec = null;
        InputStream in = null;
        BufferedReader reader = null;
        List<String> result = new ArrayList<String>();
        int exitStatus = 0;
        try {
            JSch jsch = new JSch();
            session = jsch.getSession(username, serverIp);
            session.setConfig("StrictHostKeyChecking", "no");
            session.setPassword(password);
            session.connect();
            channelExec = (ChannelExec) session.openChannel("exec");
            in = channelExec.getInputStream();
            channelExec.setCommand(environemntVariable + " " + scriptName);
            channelExec.connect();

            reader = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = reader.readLine()) != null) {
                LOGGER.info(line);
                result.add(line);
            }
            exitStatus = channelExec.getExitStatus();
            LOGGER.info("exitStatus returned: " + exitStatus);
        } catch(Exception e) {
            LOGGER.info("Error occurred while running the script: \n", e);
            exitStatus = 1;
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (in != null) {
                in.close();
            }
            if (channelExec != null) {
                channelExec.disconnect();
            }
            if (session != null) {
                session.disconnect();
            }
        }
        return exitStatus;
    }

问题在于某些 shell 脚本,从 shell 脚本返回退出状态 -1。 我在文档中发现,成功完成后,返回的退出状态为 0,如果执行不成功,返回的退出状态将大于 0。有人可以指导我退出状态 -1 表示什么吗? 由于 shell 脚本正在成功执行,但返回的退出状态为 -1。

你有没有试过阅读文档

回报:
远程命令返回的退出状态,如果命令尚未终止(或此通道类型没有命令),则返回 -1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM