sys - amend PipeCmd
This commit is contained in:
parent
65a41f6873
commit
e88b75c71f
17
sys/sys.go
17
sys/sys.go
|
@ -74,15 +74,18 @@ func RunInteractiveCmd(cmd string, withStderr bool, buffers ...*bytes.Buffer) in
|
|||
return ManageStatusCmd(icmd, icmd.Run())
|
||||
}
|
||||
|
||||
func PipeCmd(cmd1 *exec.Cmd, cmd2 *exec.Cmd, buffers ...io.Writer) {
|
||||
func PipeCmd(cmd1 *exec.Cmd, cmd2 *exec.Cmd, buffers ...io.Writer) int {
|
||||
status := -1
|
||||
// fmt.Println("> Pipe Commands")
|
||||
if len(buffers) > 0 {
|
||||
errIndex := 0
|
||||
pr, pw := io.Pipe()
|
||||
cmd1.Stdout = pw
|
||||
cmd2.Stdin = pr
|
||||
cmd2.Stdout = buffers[0]
|
||||
cmd2.Stdout = buffers[errIndex]
|
||||
if len(buffers) > 1 {
|
||||
cmd2.Stderr = buffers[1]
|
||||
errIndex = 1
|
||||
cmd2.Stderr = buffers[errIndex]
|
||||
}
|
||||
|
||||
cmd1.Start()
|
||||
|
@ -92,16 +95,20 @@ func PipeCmd(cmd1 *exec.Cmd, cmd2 *exec.Cmd, buffers ...io.Writer) {
|
|||
defer pw.Close()
|
||||
err1 := cmd1.Wait()
|
||||
if err1 != nil {
|
||||
fmt.Printf("error1 : %v\n", err1)
|
||||
buffers[errIndex].Write([]byte(fmt.Sprintf(" Error pipe in : %v\n", err1)))
|
||||
}
|
||||
}()
|
||||
|
||||
err2 := cmd2.Wait()
|
||||
if err2 != nil {
|
||||
fmt.Printf("error2 : %v\n", err2)
|
||||
buffers[errIndex].Write([]byte(fmt.Sprintf(" Error pipe out : %v\n", err2)))
|
||||
status = 1
|
||||
} else {
|
||||
status = 0
|
||||
}
|
||||
// fmt.Println("< Pipe Commands")
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func UpdateTermSize() error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user