mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: script processor support cmd and powershel by fddc
This commit is contained in:
parent
3823b3bc56
commit
45f7b17e14
@ -15,6 +15,7 @@ import java.io.*;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
@ -75,12 +76,11 @@ public abstract class AbstractScriptProcessor extends CommonBasicProcessor {
|
|||||||
boolean success = true;
|
boolean success = true;
|
||||||
String result;
|
String result;
|
||||||
|
|
||||||
//解决windows平台中文乱码
|
final Charset charset = getCharset();
|
||||||
Charset loggerCharset = SystemUtils.IS_OS_WINDOWS? Charset.forName("GBK"):StandardCharsets.UTF_8;
|
|
||||||
try (InputStream is = process.getInputStream(); InputStream es = process.getErrorStream()) {
|
try (InputStream is = process.getInputStream(); InputStream es = process.getErrorStream()) {
|
||||||
|
|
||||||
POOL.execute(() -> copyStream(is, inputBuilder, omsLogger,loggerCharset));
|
POOL.execute(() -> copyStream(is, inputBuilder, omsLogger, charset));
|
||||||
POOL.execute(() -> copyStream(es, errorBuilder, omsLogger,loggerCharset));
|
POOL.execute(() -> copyStream(es, errorBuilder, omsLogger, charset));
|
||||||
|
|
||||||
success = process.waitFor() == 0;
|
success = process.waitFor() == 0;
|
||||||
|
|
||||||
@ -113,10 +113,11 @@ public abstract class AbstractScriptProcessor extends CommonBasicProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 非下载链接,为 processInfo 生成可执行文件
|
final Charset charset = getCharset();
|
||||||
if(SystemUtils.IS_OS_WINDOWS)
|
|
||||||
|
if(charset != null)
|
||||||
{
|
{
|
||||||
try (Writer fstream = new OutputStreamWriter(new FileOutputStream(script), Charset.forName("GBK")); BufferedWriter out = new BufferedWriter(fstream)) {
|
try (Writer fstream = new OutputStreamWriter(Files.newOutputStream(script.toPath()), charset); BufferedWriter out = new BufferedWriter(fstream)) {
|
||||||
out.write(processorInfo);
|
out.write(processorInfo);
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
@ -158,4 +159,12 @@ public abstract class AbstractScriptProcessor extends CommonBasicProcessor {
|
|||||||
* @return 执行脚本的命令
|
* @return 执行脚本的命令
|
||||||
*/
|
*/
|
||||||
protected abstract String getRunCommand();
|
protected abstract String getRunCommand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认不指定
|
||||||
|
* @return Charset
|
||||||
|
*/
|
||||||
|
protected Charset getCharset() {
|
||||||
|
return StandardCharsets.UTF_8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package tech.powerjob.official.processors.impl.script;
|
package tech.powerjob.official.processors.impl.script;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* python processor
|
* python processor
|
||||||
*
|
*
|
||||||
@ -17,4 +19,9 @@ public class CMDProcessor extends AbstractScriptProcessor {
|
|||||||
protected String getRunCommand() {
|
protected String getRunCommand() {
|
||||||
return "cmd.exe";
|
return "cmd.exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Charset getCharset() {
|
||||||
|
return Charset.forName("GBK");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package tech.powerjob.official.processors.impl.script;
|
package tech.powerjob.official.processors.impl.script;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* python processor
|
* python processor
|
||||||
*
|
*
|
||||||
@ -17,4 +19,9 @@ public class PowerShellProcessor extends AbstractScriptProcessor {
|
|||||||
protected String getRunCommand() {
|
protected String getRunCommand() {
|
||||||
return "powershell.exe";
|
return "powershell.exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Charset getCharset() {
|
||||||
|
return Charset.forName("GBK");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user