add shell.Output()

This commit is contained in:
Jeff Carr 2024-03-21 19:44:38 -05:00
parent 16715e0252
commit 5553bda497
1 changed files with 33 additions and 0 deletions

33
run.go
View File

@ -212,3 +212,36 @@ func RunCmdRun(workingpath string, parts []string) error {
} }
return nil 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
}