From 5553bda4979d88f2162e9f78677a91b8f024b8f0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 21 Mar 2024 19:44:38 -0500 Subject: [PATCH] add shell.Output() --- run.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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 +}