make an exec to STDOUT
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
ec6f0a1778
commit
16715e0252
41
run.go
41
run.go
|
@ -46,7 +46,7 @@ func Run(args []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := RunPath(dir, args)
|
r := RunPath(dir, args)
|
||||||
if r.ok {
|
if r.Ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -55,27 +55,27 @@ func Run(args []string) bool {
|
||||||
var ErrorArgvEmpty error = errors.New("command was empty")
|
var ErrorArgvEmpty error = errors.New("command was empty")
|
||||||
|
|
||||||
type RunResult struct {
|
type RunResult struct {
|
||||||
ok bool
|
Ok bool
|
||||||
argv []string
|
Argv []string
|
||||||
path string
|
Path string
|
||||||
output []byte
|
Output []byte
|
||||||
err error
|
Err error
|
||||||
outerr error
|
Outerr error
|
||||||
}
|
}
|
||||||
|
|
||||||
// run, but set the working path
|
// run, but set the working path
|
||||||
func RunPath(path string, args []string) *RunResult {
|
func RunPath(path string, args []string) *RunResult {
|
||||||
r := new(RunResult)
|
r := new(RunResult)
|
||||||
r.path = path
|
r.Path = path
|
||||||
r.argv = args
|
r.Argv = args
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
r.ok = true
|
r.Ok = true
|
||||||
r.err = ErrorArgvEmpty
|
r.Err = ErrorArgvEmpty
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
if args[0] == "" {
|
if args[0] == "" {
|
||||||
r.ok = false
|
r.Ok = false
|
||||||
r.err = ErrorArgvEmpty
|
r.Err = ErrorArgvEmpty
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
thing := args[0]
|
thing := args[0]
|
||||||
|
@ -84,6 +84,7 @@ func RunPath(path string, args []string) *RunResult {
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
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
|
||||||
|
@ -95,16 +96,16 @@ func RunPath(path string, args []string) *RunResult {
|
||||||
// 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())
|
||||||
r.ok = false
|
r.Ok = false
|
||||||
r.err = err
|
r.Err = err
|
||||||
r.output = out
|
r.Output = out
|
||||||
r.outerr = outerr
|
r.Outerr = outerr
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
out, outerr := cmd.Output()
|
out, outerr := cmd.Output()
|
||||||
r.output = out
|
r.Output = out
|
||||||
r.outerr = outerr
|
r.Outerr = outerr
|
||||||
r.ok = true
|
r.Ok = true
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue