脚本,输入输出

v1.7
xueli.xue 8 years ago
parent a3bef921f7
commit b30fceb46d

@ -192,16 +192,18 @@ public class DemoGlueJobHandler extends IJobHandler {
</textarea>
<textarea class="glueSource_shell" style="display:none;" >
#!/bin/bash
echo "xxl-job: hello shell"
for item in 1 2 3
echo "脚本位置:$0"
echo "参数数量:$#"
for param in $*
do
echo "shell : $item"
echo "参数 : $param"
sleep 1s
done
echo "Good bye!"
exit 0
</textarea>
<textarea class="glueSource_python" style="display:none;" >
#!/usr/bin/python

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

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

@ -65,8 +65,11 @@ public class ScriptUtil {
* @param command
* @param scriptFile
* @param logFile
* @param params
* @return
* @throws IOException
*/
public static void execToFile(String command, String scriptFile, String logFile) throws IOException {
public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
// 标准输出print null if watchdog timeout
// 错误输出logging + 异常 still exists if watchdog timeout
// 标准输入
@ -76,12 +79,16 @@ public class ScriptUtil {
// command
CommandLine commandline = new CommandLine(command);
commandline.addArgument(scriptFile);
if (params!=null && params.length>0) {
commandline.addArguments(params);
}
// exec
DefaultExecutor exec = new DefaultExecutor();
exec.setExitValues(null);
exec.setStreamHandler(streamHandler);
int exitValue = exec.execute(commandline);
int exitValue = exec.execute(commandline); // exit code: 0=success, 1/-1=fail
return exitValue;
}
}

Loading…
Cancel
Save