Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-18 15:12:33 -06:00
parent cbafaa3c66
commit a1aa87c78a
1 changed files with 0 additions and 61 deletions

61
unix.go
View File

@ -69,64 +69,3 @@ func setGitCommands() {
}
cmds.Set(strings.Join(tmp, "\n"))
}
/*
func runCommandsOld() bool {
for _, line := range me.script {
s := strings.Join(line, " ")
log.Warn("NEED TO RUN:", s)
err, b, output := repostatus.RunCmd(repopath, line)
if err != nil {
log.Warn("ABEND EXECUTION")
log.Warn("error =", err)
log.Warn("output =", output)
return false
}
log.Warn("Returned with b =", b)
log.Warn("output was =", output)
log.Warn("RUN DONE")
}
return true
}
*/
func RunCmdNew(workingpath string, parts []string) (error, bool, string) {
log.Warn("RUN NEW:", workingpath, parts)
return RunCmd(workingpath, parts)
}
func RunCmd(workingpath string, parts []string) (error, bool, string) {
log.Warn("RUN CMD:", workingpath, parts)
if len(parts) == 0 {
log.Warn("command line was empty")
return errors.New("empty"), false, ""
}
if parts[0] == "" {
log.Warn("command line was empty")
return errors.New("empty"), false, ""
}
thing := parts[0]
parts = parts[1:]
log.Warn("working path =", workingpath, "thing =", thing, "cmdline =", parts)
// Create the command
cmd := exec.Command(thing, parts...)
// Set the working directory
cmd.Dir = workingpath
// Execute the command
output, err := cmd.CombinedOutput()
if err != nil {
log.Error(err)
log.Warn("output was", string(output))
log.Warn("cmd exited with error", err)
return err, false, string(output)
}
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output
return nil, true, tmp
}