From 226eb6554f293ef042298a51d9598ee76891796e Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Tue, 29 Nov 2016 16:55:32 -0800 Subject: [PATCH] Support for Run() convenience function --- util.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 util.go diff --git a/util.go b/util.go new file mode 100644 index 000000000..4763ff715 --- /dev/null +++ b/util.go @@ -0,0 +1,22 @@ +package process + +import ( + . "github.com/tendermint/go-common" +) + +// Runs a command and gets the result. +func Run(command string, args []string) (string, bool, error) { + outFile := NewBufferCloser(nil) + proc, err := StartProcess("", command, args, nil, outFile) + if err != nil { + return "", false, err + } + + <-proc.WaitCh + + if proc.ExitState.Success() { + return string(outFile.Bytes()), true, nil + } else { + return string(outFile.Bytes()), false, nil + } +}