return a struct
This commit is contained in:
parent
1ff1045445
commit
f163738c86
50
run.go
50
run.go
|
@ -50,8 +50,8 @@ func Run(args []string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
err = RunPath(dir, args)
|
||||
if err == nil {
|
||||
r := RunPath(dir, args)
|
||||
if r.ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -59,13 +59,29 @@ func Run(args []string) bool {
|
|||
|
||||
var ErrorArgvEmpty error = errors.New("command was empty")
|
||||
|
||||
type RunResult struct {
|
||||
ok bool
|
||||
argv []string
|
||||
path string
|
||||
output []byte
|
||||
err error
|
||||
outerr error
|
||||
}
|
||||
|
||||
// run, but set the working path
|
||||
func RunPath(path string, args []string) error {
|
||||
func RunPath(path string, args []string) *RunResult {
|
||||
r := new(RunResult)
|
||||
r.path = path
|
||||
r.argv = args
|
||||
if len(args) == 0 {
|
||||
return ErrorArgvEmpty
|
||||
r.ok = true
|
||||
r.err = ErrorArgvEmpty
|
||||
return r
|
||||
}
|
||||
if args[0] == "" {
|
||||
return ErrorArgvEmpty
|
||||
r.ok = false
|
||||
r.err = ErrorArgvEmpty
|
||||
return r
|
||||
}
|
||||
thing := args[0]
|
||||
parts := args[1:]
|
||||
|
@ -76,17 +92,25 @@ func RunPath(path string, args []string) error {
|
|||
log.Info("path =", path, "cmd =", strings.Join(args, " "))
|
||||
if err := cmd.Run(); err != nil {
|
||||
// Handle error if the command execution fails
|
||||
log.Info("RunPath() failed")
|
||||
// log.Info("RunPath() failed")
|
||||
// log.Info("cmd.Enviorn =", cmd.Environ())
|
||||
out, outerr := cmd.Output()
|
||||
log.Info("cmd.output =", out)
|
||||
log.Info("cmd.output err=", outerr)
|
||||
log.Info("path =", path)
|
||||
log.Info("args =", args)
|
||||
log.Info("err =", err.Error())
|
||||
return err
|
||||
// log.Info("cmd.output =", out)
|
||||
// log.Info("cmd.output err=", outerr)
|
||||
// log.Info("path =", path)
|
||||
// log.Info("args =", args)
|
||||
// log.Info("err =", err.Error())
|
||||
r.ok = false
|
||||
r.err = err
|
||||
r.output = out
|
||||
r.outerr = outerr
|
||||
return r
|
||||
}
|
||||
return nil
|
||||
out, outerr := cmd.Output()
|
||||
r.output = out
|
||||
r.outerr = outerr
|
||||
r.ok = true
|
||||
return r
|
||||
}
|
||||
|
||||
func (cmd *OldShell) Run(cmdline string) string {
|
||||
|
|
Loading…
Reference in New Issue