added err and lookup
parent
1c1151ffd6
commit
214a77730b
15
lib.go
15
lib.go
|
@ -390,14 +390,18 @@ func ExecStr(str string, opts ...*Opts) (string, error) {
|
||||||
|
|
||||||
cmdwd := opt.Wd
|
cmdwd := opt.Wd
|
||||||
|
|
||||||
prepCmd := func(l Line) *exec.Cmd {
|
prepCmd := func(l Line) (*exec.Cmd, error) {
|
||||||
cmd := exec.Command(l.Tokens[0], l.Tokens[1:]...)
|
str, err := exec.LookPath(l.Tokens[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cmd := exec.Command(str, l.Tokens[1:]...)
|
||||||
cmd.Stdout = log.Writer()
|
cmd.Stdout = log.Writer()
|
||||||
cmd.Stderr = log.Writer()
|
cmd.Stderr = log.Writer()
|
||||||
cmd.Dir = cmdwd
|
cmd.Dir = cmdwd
|
||||||
opt.SetupProc(cmd)
|
opt.SetupProc(cmd)
|
||||||
ret = append(ret, cmd)
|
ret = append(ret, cmd)
|
||||||
return cmd
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lines, err := Lines(str)
|
lines, err := Lines(str)
|
||||||
|
@ -423,7 +427,10 @@ func ExecStr(str string, opts ...*Opts) (string, error) {
|
||||||
log.Printf("CMDWD NOW IS: %s", cmdwd)
|
log.Printf("CMDWD NOW IS: %s", cmdwd)
|
||||||
continue
|
continue
|
||||||
case LINETYPE_SERIAL, LINETYPE_PARALLEL:
|
case LINETYPE_SERIAL, LINETYPE_PARALLEL:
|
||||||
cmd := prepCmd(l)
|
cmd, err := prepCmd(l)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
if opt.Debug {
|
if opt.Debug {
|
||||||
log.Printf("Running %s from dir %s with params %v", cmd.Path, cmd.Dir, cmd.Args)
|
log.Printf("Running %s from dir %s with params %v", cmd.Path, cmd.Dir, cmd.Args)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue