add simple

master
Paulo Simão 2021-10-30 08:37:31 -03:00
parent 93c21fac65
commit e855d65d60
1 changed files with 28 additions and 0 deletions

28
lib.go
View File

@ -174,6 +174,12 @@ func Lines(str string) ([]Line, error) {
line.LType = LINETYPE_CHANGEWD line.LType = LINETYPE_CHANGEWD
} }
if runtime.GOOS == "windows" && (line.LType == LINETYPE_SERIAL || line.LType == LINETYPE_PARALLEL) {
if !strings.HasSuffix(line.Tokens[0], ".exe") {
line.Tokens[0] = line.Tokens[0] + ".exe"
}
}
ret = append(ret, line) ret = append(ret, line)
} }
@ -411,3 +417,25 @@ func Kill(p int) error {
} }
} }
// Simple Runs a simple command line
func Simple(str string) (*exec.Cmd, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}
lines, err := Lines(str)
if err != nil {
return nil, err
}
l := lines[0]
fqncmd, err := exec.LookPath(l.Tokens[0])
if err != nil {
fqncmd = filepath.Join(wd, l.Tokens[0])
}
cmd := exec.Command(fqncmd, l.Tokens[1:]...)
return cmd, nil
}