add shell.Output()
This commit is contained in:
parent
16715e0252
commit
5553bda497
33
run.go
33
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue