Commit a32245c5 by guo_minglei@163.com

修改执行命令

parent 787cd9f8
......@@ -15,7 +15,6 @@ import com.byit.job.utils.PlaceholderUtils;
import com.byit.dto.web.ReturnResult;
import com.byit.pool.RunThreadPool;
import com.byit.rpc.remoting.provider.annotation.RpcService;
import com.byit.utils.CmdUtil;
import com.byit.utils.ServiceInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.csource.common.MyException;
......@@ -107,7 +106,7 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
if(scriptParamAndPlaceholderDto != null){
command = PlaceholderUtils.commandReplace(command,scriptParamAndPlaceholderDto.getParam());
}
List<String> cmdList = Arrays.asList(CmdUtil.partitionCommandLine(command));
List<String> cmdList = Arrays.asList(command.split(" "));
MythJobProcess mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId(), stringRedisTemplate);
//保存日志
String logData = mythJobProcess.call();
......
package com.byit.utils;
import java.util.ArrayList;
public class CmdUtil {
public static String[] partitionCommandLine(final String command) {
final ArrayList<String> commands = new ArrayList<>();
int index = 0;
StringBuffer buffer = new StringBuffer(command.length());
boolean isApos = false;
boolean isQuote = false;
while (index < command.length()) {
final char c = command.charAt(index);
switch (c) {
case ' ':
if (!isQuote && !isApos) {
final String arg = buffer.toString();
buffer = new StringBuffer(command.length() - index);
if (arg.length() > 0) {
commands.add(arg);
}
} else {
buffer.append(c);
}
break;
case '\'':
if (!isQuote) {
isApos = !isApos;
} else {
buffer.append(c);
}
break;
case '"':
if (!isApos) {
isQuote = !isQuote;
} else {
buffer.append(c);
}
break;
default:
buffer.append(c);
}
index++;
}
if (buffer.length() > 0) {
final String arg = buffer.toString();
commands.add(arg);
}
return commands.toArray(new String[commands.size()]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment