[ Agent ] [ Executor ] - 增加Pipeline部分的代码

This commit is contained in:
zeaslity
2023-10-18 09:26:58 +08:00
parent 0e8f633166
commit be01eb28a9
8 changed files with 192 additions and 94 deletions

View File

@@ -2,9 +2,11 @@ package executor
import (
"bufio"
"bytes"
"fmt"
"io"
"os/exec"
"strings"
)
// AllCommandExecutor 正确或者错误的信息全部收集,共同返回
@@ -100,6 +102,39 @@ func FormatAllCommandExecutor(singleLineCommand []string) ([]string, error) {
return resultSlice, resultError
}
func PipelineCommandExecutor() {
cmd1 := exec.Command("ps", "aux")
cmd2 := exec.Command("grep", "apipe")
var outputBuf1 bytes.Buffer
cmd1.Stdout = &outputBuf1
if err := cmd1.Start(); err != nil {
fmt.Printf("Error: The first command can not be startup %s\n", err)
return
}
if err := cmd1.Wait(); err != nil {
fmt.Printf("Error: Couldn't wait for the first command: %s\n", err)
return
}
cmd2.Stdin = &outputBuf1
var outputBuf2 bytes.Buffer
cmd2.Stdout = &outputBuf2
if err := cmd2.Start(); err != nil {
fmt.Printf("Error: The second command can not be startup: %s\n", err)
return
}
if err := cmd2.Wait(); err != nil {
fmt.Printf("Error: Couldn't wait for the second command: %s\n", err)
return
}
s := outputBuf2.String()
split := strings.Split(s, "\n")
BasicPrettyPrint(true, split)
}
// PureResultSingleExecute 执行单行命令,忽略输出,只对执行成功与否负责
func PureResultSingleExecute(singleCommand []string) (resultOK bool) {