脚本,输入输出
This commit is contained in:
parent
a3bef921f7
commit
b30fceb46d
|
@ -192,16 +192,18 @@ public class DemoGlueJobHandler extends IJobHandler {
|
||||||
</textarea>
|
</textarea>
|
||||||
<textarea class="glueSource_shell" style="display:none;" >
|
<textarea class="glueSource_shell" style="display:none;" >
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "xxl-job: hello shell"
|
echo "xxl-job: hello shell"
|
||||||
|
|
||||||
for item in 1 2 3
|
echo "脚本位置:$0"
|
||||||
|
echo "参数数量:$#"
|
||||||
|
for param in $*
|
||||||
do
|
do
|
||||||
echo "shell : $item"
|
echo "参数 : $param"
|
||||||
sleep 1s
|
sleep 1s
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Good bye!"
|
echo "Good bye!"
|
||||||
|
exit 0
|
||||||
</textarea>
|
</textarea>
|
||||||
<textarea class="glueSource_python" style="display:none;" >
|
<textarea class="glueSource_python" style="display:none;" >
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
|
@ -304,7 +304,7 @@ $(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// GLUE模式开启
|
// 运行模式
|
||||||
$(".glueType").change(function(){
|
$(".glueType").change(function(){
|
||||||
// executorHandler
|
// executorHandler
|
||||||
var $executorHandler = $(this).parents("form").find("input[name='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());
|
String logFileName = XxlJobFileAppender.filePath.concat(XxlJobFileAppender.contextHolder.get());
|
||||||
|
|
||||||
// invoke
|
// invoke
|
||||||
ScriptUtil.execToFile(cmd, scriptFileName, logFileName);
|
int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, params);
|
||||||
return ReturnT.SUCCESS;
|
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 command
|
||||||
* @param scriptFile
|
* @param scriptFile
|
||||||
* @param logFile
|
* @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)
|
// 标准输出:print (null if watchdog timeout)
|
||||||
// 错误输出:logging + 异常 (still exists if watchdog timeout)
|
// 错误输出:logging + 异常 (still exists if watchdog timeout)
|
||||||
// 标准输入
|
// 标准输入
|
||||||
|
@ -76,12 +79,16 @@ public class ScriptUtil {
|
||||||
// command
|
// command
|
||||||
CommandLine commandline = new CommandLine(command);
|
CommandLine commandline = new CommandLine(command);
|
||||||
commandline.addArgument(scriptFile);
|
commandline.addArgument(scriptFile);
|
||||||
|
if (params!=null && params.length>0) {
|
||||||
|
commandline.addArguments(params);
|
||||||
|
}
|
||||||
|
|
||||||
// exec
|
// exec
|
||||||
DefaultExecutor exec = new DefaultExecutor();
|
DefaultExecutor exec = new DefaultExecutor();
|
||||||
exec.setExitValues(null);
|
exec.setExitValues(null);
|
||||||
exec.setStreamHandler(streamHandler);
|
exec.setStreamHandler(streamHandler);
|
||||||
int exitValue = exec.execute(commandline);
|
int exitValue = exec.execute(commandline); // exit code: 0=success, 1/-1=fail
|
||||||
|
return exitValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue