[agent-go] [executor] real time executor
This commit is contained in:
40
agent-go/executor/RealTimeExecutor.go
Normal file
40
agent-go/executor/RealTimeExecutor.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package executor
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func ReadTimeOutput(singleLineCommand []string) {
|
||||
|
||||
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go copyOutput(stdout)
|
||||
go copyOutput(stderr)
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func copyOutput(r io.Reader) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
fmt.Println(scanner.Text())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user