[ Agent ] [ Executor ] 优化Excuetor部分的代码
This commit is contained in:
@@ -36,33 +36,37 @@ func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) {
|
||||
|
||||
// result
|
||||
var resultSlice []string
|
||||
var resultError error
|
||||
|
||||
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.ErrorF("command %v stdout error => %v", singleLineCommand, err)
|
||||
resultError = err
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
log.ErrorF("command %v stderr error => %v", singleLineCommand, err)
|
||||
resultError = err
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.ErrorF("command %v runtime error => %v", singleLineCommand, err)
|
||||
}
|
||||
|
||||
resultSlice = append(resultSlice, "👇👇👇 命令 输出 信息如下 👇👇👇")
|
||||
resultSlice = append(resultSlice, collectOutput(stdout, resultSlice)...)
|
||||
resultSlice = append(resultSlice, "👇👇👇 命令 错误 信息如下 👇👇👇")
|
||||
resultSlice = append(resultSlice, collectOutput(stderr, resultSlice)...)
|
||||
resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓")
|
||||
resultSlice = collectOutput(stdout, resultSlice)
|
||||
resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓")
|
||||
resultSlice = collectOutput(stderr, resultSlice)
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.ErrorF("command %v result error => %v", singleLineCommand, err)
|
||||
resultError = err
|
||||
}
|
||||
|
||||
log.DebugF("real time exec result are %v", resultSlice)
|
||||
|
||||
return resultSlice, nil
|
||||
return resultSlice, resultError
|
||||
}
|
||||
|
||||
func realTimeOutput(r io.Reader) {
|
||||
|
||||
Reference in New Issue
Block a user