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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = RunPath(dir, args)
|
r := RunPath(dir, args)
|
||||||
if err == nil {
|
if r.ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -59,13 +59,29 @@ func Run(args []string) bool {
|
||||||
|
|
||||||
var ErrorArgvEmpty error = errors.New("command was empty")
|
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
|
// 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 {
|
if len(args) == 0 {
|
||||||
return ErrorArgvEmpty
|
r.ok = true
|
||||||
|
r.err = ErrorArgvEmpty
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
if args[0] == "" {
|
if args[0] == "" {
|
||||||
return ErrorArgvEmpty
|
r.ok = false
|
||||||
|
r.err = ErrorArgvEmpty
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
thing := args[0]
|
thing := args[0]
|
||||||
parts := args[1:]
|
parts := args[1:]
|
||||||
|
@ -76,17 +92,25 @@ func RunPath(path string, args []string) error {
|
||||||
log.Info("path =", path, "cmd =", strings.Join(args, " "))
|
log.Info("path =", path, "cmd =", strings.Join(args, " "))
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
// Handle error if the command execution fails
|
// Handle error if the command execution fails
|
||||||
log.Info("RunPath() failed")
|
// log.Info("RunPath() failed")
|
||||||
// log.Info("cmd.Enviorn =", cmd.Environ())
|
// log.Info("cmd.Enviorn =", cmd.Environ())
|
||||||
out, outerr := cmd.Output()
|
out, outerr := cmd.Output()
|
||||||
log.Info("cmd.output =", out)
|
// log.Info("cmd.output =", out)
|
||||||
log.Info("cmd.output err=", outerr)
|
// log.Info("cmd.output err=", outerr)
|
||||||
log.Info("path =", path)
|
// log.Info("path =", path)
|
||||||
log.Info("args =", args)
|
// log.Info("args =", args)
|
||||||
log.Info("err =", err.Error())
|
// log.Info("err =", err.Error())
|
||||||
return err
|
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 {
|
func (cmd *OldShell) Run(cmdline string) string {
|
||||||
|
|
Loading…
Reference in New Issue