Linux shell 脚本的退出状态 -1

Exit status -1 from a Linux shell script

我在我们的一台服务器中有一些 Unix shell 脚本,我使用 Spring Boot 编写了一个 Java 程序,该程序部署在另一个应用程序中 server.From 我的Spring 启动应用程序,我在另一台服务器上远程执行 shell 脚本。我的程序如下:

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。

你有没有试过阅读documentation

Returns:
the exitstatus returned by the remote command, or -1, if the command not yet terminated (or this channel type has no command).