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 { if wait {
<-proc.WaitCh <-proc.WaitCh
output := pcm.ReadOutput(proc)
if proc.ExitState == nil { if proc.ExitState == nil {
return &ResponseRunProcess{ return &ResponseRunProcess{
Success: true, Success: true,
Output: output,
}, nil }, nil
} else { } else {
return &ResponseRunProcess{ return &ResponseRunProcess{
Success: proc.ExitState.Success(), // Would be always false? Success: proc.ExitState.Success(), // Would be always false?
Output: output,
}, nil }, nil
} }
} else { } else {
return &ResponseRunProcess{}, nil return &ResponseRunProcess{
Success: true,
Output: "",
}, nil
} }
} }

View File

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

View File

@ -124,6 +124,11 @@ func cliRunProcess(c *cli.Context) {
fmt.Printf("%v failure. %v\n", remote, err) fmt.Printf("%v failure. %v\n", remote, err)
} else { } else {
fmt.Printf("%v success. %v\n", remote, response) 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" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"time" "time"
@ -83,6 +84,14 @@ func Create(mode int, label string, execPath string, args []string, input string
return proc, nil 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 { func Stop(proc *Process, kill bool) error {
defer proc.OutputFile.Close() defer proc.OutputFile.Close()
if kill { if kill {