在 spring 批处理侦听器中执行 shell 命令

问题描述

我正在使用带有 Java 7 的 Spring Batch 来做一些事情。 当我的批处理完成生成结果文件时,我想执行一些 linux 命令行(将其复制到 CFT 服务器中)。 我为侦听器添加了以下代码行:

@豆 public JobExecutionListener envoieCFT() {

    JobExecutionListener listener = new JobExecutionListener() {
        @Override
        public void beforeJob(JobExecution jobExecution) {}

        @Override
        public void afterJob(JobExecution jobExecution) {
            
            final String command ="scp <file path> <user>@<ip@>:< where to copy the file>";
            boolean isWindows = System.getProperty("os.name")
                      .toLowerCase().startsWith("windows");
            Process process;
            if (!isWindows) {
                try {
                    process = Runtime.getRuntime()
                      .exec(String.format(command));
                } catch (IOException e) {
                    e.printstacktrace();
                }
            }
            System.out.println("Job finished notification");
        }
    };

    return listener ;
}

它根本不起作用,有人遇到过同样的问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)