2016-11-29 16:55:32 -08:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
2017-04-18 17:56:05 -04:00
|
|
|
. "github.com/tendermint/tmlibs/common"
|
2016-11-29 16:55:32 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Runs a command and gets the result.
|
2016-12-06 02:08:05 -08:00
|
|
|
func Run(dir string, command string, args []string) (string, bool, error) {
|
2016-11-29 16:55:32 -08:00
|
|
|
outFile := NewBufferCloser(nil)
|
2016-12-06 02:08:05 -08:00
|
|
|
proc, err := StartProcess("", dir, command, args, nil, outFile)
|
2016-11-29 16:55:32 -08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|