From 75697034bd415843bc51a2c1509ddb31809d6c5e Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 17 Apr 2015 10:27:17 -0700 Subject: [PATCH] ReadOutput for process, and --wait will read process output --- cmd/barak/main.go | 8 +++++++- cmd/barak/types/responses.go | 1 + cmd/debora/main.go | 5 +++++ process/process.go | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/barak/main.go b/cmd/barak/main.go index b11be7f6..c4e4ef2e 100644 --- a/cmd/barak/main.go +++ b/cmd/barak/main.go @@ -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 } } diff --git a/cmd/barak/types/responses.go b/cmd/barak/types/responses.go index aae29925..6889a7f9 100644 --- a/cmd/barak/types/responses.go +++ b/cmd/barak/types/responses.go @@ -12,6 +12,7 @@ type ResponseStatus struct { type ResponseRunProcess struct { Success bool + Output string } type ResponseStopProcess struct { diff --git a/cmd/debora/main.go b/cmd/debora/main.go index 603352e9..b7bc62c2 100644 --- a/cmd/debora/main.go +++ b/cmd/debora/main.go @@ -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)") + } } } } diff --git a/process/process.go b/process/process.go index c4e8a759..15f63c4d 100644 --- a/process/process.go +++ b/process/process.go @@ -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 {