[ Agent ] [ Executor ] 优化Executor部分的代码 - 2
This commit is contained in:
@@ -79,28 +79,31 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
||||
var output []byte
|
||||
var err error
|
||||
|
||||
for i, command := range pipeLineCommand {
|
||||
|
||||
cmd := exec.Command(command[0], command[1:]...)
|
||||
cmd.Stdin = bytes.NewReader(output)
|
||||
|
||||
output, err = cmd.Output()
|
||||
if err != nil {
|
||||
return strings.Split(string(output), "\n"), err
|
||||
for _, pipeCommand := range pipeLineCommand {
|
||||
if len(pipeCommand) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if i == len(pipeLineCommand)-1 {
|
||||
return strings.Split(string(output), "\n"), nil
|
||||
command := exec.Command(pipeCommand[0], pipeCommand[1:]...)
|
||||
if len(output) > 0 {
|
||||
command.Stdin = bytes.NewBuffer(output)
|
||||
}
|
||||
|
||||
output, err = command.Output()
|
||||
if err != nil {
|
||||
log.ErrorF("Pipeline Command Exec Error => %v", err.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user