added err and lookup

master
Paulo Simão 2022-02-16 21:22:54 -03:00
parent 1c1151ffd6
commit 214a77730b
1 changed files with 11 additions and 4 deletions

15
lib.go
View File

@ -390,14 +390,18 @@ func ExecStr(str string, opts ...*Opts) (string, error) {
cmdwd := opt.Wd
prepCmd := func(l Line) *exec.Cmd {
cmd := exec.Command(l.Tokens[0], l.Tokens[1:]...)
prepCmd := func(l Line) (*exec.Cmd, error) {
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.Stderr = log.Writer()
cmd.Dir = cmdwd
opt.SetupProc(cmd)
ret = append(ret, cmd)
return cmd
return cmd, nil
}
lines, err := Lines(str)
@ -423,7 +427,10 @@ func ExecStr(str string, opts ...*Opts) (string, error) {
log.Printf("CMDWD NOW IS: %s", cmdwd)
continue
case LINETYPE_SERIAL, LINETYPE_PARALLEL:
cmd := prepCmd(l)
cmd, err := prepCmd(l)
if err != nil {
return "", err
}
if opt.Debug {
log.Printf("Running %s from dir %s with params %v", cmd.Path, cmd.Dir, cmd.Args)
}