[ Agent ] [ Executor ] 优化Executor部分的代码 - 2

This commit is contained in:
zeaslity
2023-08-14 11:11:20 +08:00
parent 7ca5e232bf
commit 129886bd57
4 changed files with 17 additions and 18 deletions

View File

@@ -79,28 +79,31 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
var output []byte
var err error
for i, command := range pipeLineCommand {
for _, pipeCommand := range pipeLineCommand {
if len(pipeCommand) == 0 {
continue
}
cmd := exec.Command(command[0], command[1:]...)
cmd.Stdin = bytes.NewReader(output)
command := exec.Command(pipeCommand[0], pipeCommand[1:]...)
if len(output) > 0 {
command.Stdin = bytes.NewBuffer(output)
}
output, err = cmd.Output()
output, err = command.Output()
if err != nil {
return strings.Split(string(output), "\n"), err
log.ErrorF("Pipeline Command Exec Error => %v", err.Error())
break
}
}
if i == len(pipeLineCommand)-1 {
return strings.Split(string(output), "\n"), nil
}
}
return []string{}, nil
return []string{string(output)}, err
}
func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) {
var res []string
for _, singleLineCommand := range multiLineCommandExecutor {
singleLogs, err := SingleLineCommandExecutor(singleLineCommand)
singleLogs, err := AllOutputCommandExecutor(singleLineCommand)
res = append(res, singleLogs...)
if err != nil {

View File

@@ -54,7 +54,7 @@ func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) {
log.ErrorF("command %v runtime error => %v", singleLineCommand, err)
}
resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓")
resultSlice = append(resultSlice, fmt.Sprintf("命令为 => %v", singleLineCommand), "↓↓↓ 命令 输出 如下 ↓↓↓")
resultSlice = collectOutput(stdout, resultSlice)
resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓")
resultSlice = collectOutput(stderr, resultSlice)

View File

@@ -116,7 +116,7 @@ public class ExecutionController {
null,
commandList,
completeCommandList,
false,
true,
false
);

View File

@@ -3,14 +3,10 @@ package io.wdd.server;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
@SpringBootTest
class ServerApplicationTests {
@Resource
AsyncExecutionService asyncExecutionService;
@Test
void testCoreExecutionCompleteScript() {