diff --git a/run.go b/run.go index 4d674c5..d023070 100644 --- a/run.go +++ b/run.go @@ -212,3 +212,36 @@ func RunCmdRun(workingpath string, parts []string) error { } return nil } + +// run, but set the working path +func Output(path string, args []string) *RunResult { + r := new(RunResult) + r.Path = path + r.Argv = args + if len(args) == 0 { + r.Ok = true + r.Err = ErrorArgvEmpty + return r + } + if args[0] == "" { + r.Ok = false + r.Err = ErrorArgvEmpty + return r + } + thing := args[0] + parts := args[1:] + cmd := exec.Command(thing, parts...) + cmd.Dir = path + output, err := cmd.CombinedOutput() + + if err := cmd.Run(); err != nil { + r.Ok = false + r.Err = err + r.Output = output + return r + } + r.Output = output + r.Err = err + r.Ok = true + return r +}