[ Service ] [ Executor ] 重构Executor部分

This commit is contained in:
zeaslity
2023-08-14 10:09:23 +08:00
parent a2b6b01fd3
commit 92390b4d6f
14 changed files with 72 additions and 462 deletions

View File

@@ -57,7 +57,7 @@ func Execute(em *ExecutionMessage) ([]string, error) {
realCommand = em.MultiLineCommand
} else {
// 单行命令
resultLog, err = SingleLineCommandExecutor(em.SingleLineCommand)
resultLog, err = AllOutputCommandExecutor(em.SingleLineCommand)
realCommand = [][]string{em.SingleLineCommand}
}
}

View File

@@ -32,7 +32,10 @@ func ReadTimeCommandExecutor(singleLineCommand []string) {
}
// AllOutputCommandExecutor 收集全部执行结果、错误并且返回
func AllOutputCommandExecutor(singleLineCommand []string) []string {
func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) {
// result
var resultSlice []string
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
stdout, err := cmd.StdoutPipe()
@@ -48,17 +51,18 @@ func AllOutputCommandExecutor(singleLineCommand []string) []string {
log.ErrorF("command %v runtime error => %v", singleLineCommand, err)
}
var resultSlice []string
resultSlice = append(resultSlice, "👇👇👇 命令 输出 信息如下 👇👇👇")
resultSlice = append(resultSlice, collectOutput(stdout, resultSlice)...)
resultSlice = append(resultSlice, "👇👇👇 命令 错误 信息如下 👇👇👇")
resultSlice = append(resultSlice, collectOutput(stderr, resultSlice)...)
if err := cmd.Wait(); err != nil {
log.ErrorF("command %v result error => %v", singleLineCommand, err)
}
//log.DebugF("real time exec result are %v", resultSlice)
log.DebugF("real time exec result are %v", resultSlice)
return resultSlice
return resultSlice, nil
}
func realTimeOutput(r io.Reader) {