ReadOutput for process, and --wait will read process output

This commit is contained in:
Jae Kwon 2015-04-17 10:27:17 -07:00
parent 02bc535e0e
commit 75697034bd
4 changed files with 22 additions and 1 deletions

View File

@ -176,17 +176,23 @@ func RunProcess(wait bool, label string, execPath string, args []string, input s
if wait {
<-proc.WaitCh
output := pcm.ReadOutput(proc)
if proc.ExitState == nil {
return &ResponseRunProcess{
Success: true,
Output: output,
}, nil
} else {
return &ResponseRunProcess{
Success: proc.ExitState.Success(), // Would be always false?
Output: output,
}, nil
}
} else {
return &ResponseRunProcess{}, nil
return &ResponseRunProcess{
Success: true,
Output: "",
}, nil
}
}

View File

@ -12,6 +12,7 @@ type ResponseStatus struct {
type ResponseRunProcess struct {
Success bool
Output string
}
type ResponseStopProcess struct {

View File

@ -124,6 +124,11 @@ func cliRunProcess(c *cli.Context) {
fmt.Printf("%v failure. %v\n", remote, err)
} else {
fmt.Printf("%v success. %v\n", remote, response)
if response.Output != "" {
fmt.Println(response.Output)
} else {
fmt.Println("(no output)")
}
}
}
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"time"
@ -83,6 +84,14 @@ func Create(mode int, label string, execPath string, args []string, input string
return proc, nil
}
func ReadOutput(proc *Process) string {
output, err := ioutil.ReadFile(proc.OutputPath)
if err != nil {
return fmt.Sprintf("ERROR READING OUTPUT: %v", err)
}
return string(output)
}
func Stop(proc *Process, kill bool) error {
defer proc.OutputFile.Close()
if kill {