Kaynağa Gözat

脚本,输入输出

xueli.xue 8 yıl önce
ebeveyn
işleme
b30fceb46d

+ 5 - 3
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl Dosyayı Görüntüle

@@ -192,16 +192,18 @@ public class DemoGlueJobHandler extends IJobHandler {
192 192
 </textarea>
193 193
 <textarea class="glueSource_shell" style="display:none;" >
194 194
 #!/bin/bash
195
-
196 195
 echo "xxl-job: hello shell"
197 196
 
198
-for item in 1 2 3
197
+echo "脚本位置:$0"
198
+echo "参数数量:$#"
199
+for param in $*
199 200
 do
200
-    echo "shell : $item"
201
+    echo "参数 : $param"
201 202
     sleep 1s
202 203
 done
203 204
 
204 205
 echo "Good bye!"
206
+exit 0
205 207
 </textarea>
206 208
 <textarea class="glueSource_python" style="display:none;" >
207 209
 #!/usr/bin/python

+ 1 - 1
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js Dosyayı Görüntüle

@@ -304,7 +304,7 @@ $(function() {
304 304
 	});
305 305
 
306 306
 
307
-    // GLUE模式开启
307
+    // 运行模式
308 308
     $(".glueType").change(function(){
309 309
 		// executorHandler
310 310
         var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");

+ 3 - 2
xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java Dosyayı Görüntüle

@@ -48,8 +48,9 @@ public class ScriptJobHandler extends IJobHandler {
48 48
         String logFileName = XxlJobFileAppender.filePath.concat(XxlJobFileAppender.contextHolder.get());
49 49
 
50 50
         // invoke
51
-        ScriptUtil.execToFile(cmd, scriptFileName, logFileName);
52
-        return ReturnT.SUCCESS;
51
+        int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, params);
52
+        ReturnT<String> result = (exitValue==0)?ReturnT.SUCCESS:new ReturnT<String>(ReturnT.FAIL_CODE, "script exit value("+exitValue+") is failed");
53
+        return result;
53 54
     }
54 55
 
55 56
 }

+ 9 - 2
xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java Dosyayı Görüntüle

@@ -65,8 +65,11 @@ public class ScriptUtil {
65 65
      * @param command
66 66
      * @param scriptFile
67 67
      * @param logFile
68
+     * @param params
69
+     * @return
70
+     * @throws IOException
68 71
      */
69
-    public static void execToFile(String command, String scriptFile, String logFile) throws IOException {
72
+    public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
70 73
         // 标准输出:print (null if watchdog timeout)
71 74
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
72 75
         // 标准输入
@@ -76,12 +79,16 @@ public class ScriptUtil {
76 79
         // command
77 80
         CommandLine commandline = new CommandLine(command);
78 81
         commandline.addArgument(scriptFile);
82
+        if (params!=null && params.length>0) {
83
+            commandline.addArguments(params);
84
+        }
79 85
 
80 86
         // exec
81 87
         DefaultExecutor exec = new DefaultExecutor();
82 88
         exec.setExitValues(null);
83 89
         exec.setStreamHandler(streamHandler);
84
-        int exitValue = exec.execute(commandline);
90
+        int exitValue = exec.execute(commandline);  // exit code: 0=success, 1/-1=fail
91
+        return exitValue;
85 92
     }
86 93
 
87 94
 }