XXL-JOB执行命令并回显
XXL-JOB执行命令并回显
package com.xxl.job.service.handler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.log.XxlJobLogger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class DemoGlueJobHandler extends IJobHandler {
    @Override
    public ReturnT<String> execute(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");

        Process p;
				def commands = ["/bin/bash","-c",param] as String[]

        try {
						p = Runtime.getRuntime().exec(commands);

            InputStream fis = p.getInputStream();
            InputStreamReader isr = new InputStreamReader(fis);
            BufferedReader br = new BufferedReader(isr);
            String line = null;

            while ((line = br.readLine()) != null) {
                XxlJobLogger.log(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return ReturnT.SUCCESS;
    }
}