diff options
| author | Jeff Carr <[email protected]> | 2024-01-10 18:18:01 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-10 18:18:01 -0600 |
| commit | 1c02e4d05fa5fb20ba3d38710da141f7d82d701f (patch) | |
| tree | c0a0c56ac737239c11feb3b7cb9c56f641448d8f /unix.go | |
| parent | 54d8059a743f2ec747cf8c8506ab660eee45f437 (diff) | |
things are now almost automatic
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'unix.go')
| -rw-r--r-- | unix.go | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -102,3 +102,38 @@ func splitVersion(version string) (a, b, c string) { return parts[0], parts[1], parts[2] } } + +func runCmd(path string, parts []string) (bool, string) { + if len(parts) == 0 { + log.Warn("command line was empty") + return false, "" + } + if parts[0] == "" { + log.Warn("command line was empty") + return false, "" + } + thing := parts[0] + parts = parts[1:] + + log.Warn("path =", path, "thing =", thing, "cmdline =", parts) + // Create the command + cmd := exec.Command(thing, parts...) + + // Set the working directory + cmd.Dir = fullpath(path) + + // Execute the command + output, err := cmd.CombinedOutput() + if err != nil { + log.Error(err) + log.Warn("output was", output) + log.Warn("cmd exited with error", err) + return false, string(output) + } + + tmp := string(output) + tmp = strings.TrimSpace(tmp) + + // Print the output + return true, tmp +} |
