diff options
| author | Jeff Carr <[email protected]> | 2024-01-18 14:21:02 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-18 14:21:02 -0600 |
| commit | 209074a2448b17dfbd6d92057e4410bc4309830d (patch) | |
| tree | acb4e470b4c2bb328ab77bef80f7d82897556d24 /unix.go | |
| parent | afcf7f87aa8f35ca2fe69c54373d28788ba03f84 (diff) | |
strangely time.Sleep() doesn't seem to work
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'unix.go')
| -rw-r--r-- | unix.go | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -1,9 +1,13 @@ package main import ( - "go.wit.com/log" + "os" + "os/exec" + "time" "strings" + "errors" + "go.wit.com/log" "go.wit.com/lib/gui/repostatus" ) @@ -87,3 +91,46 @@ func runCommandsOld() bool { return true } */ + +func RunCmdNew(workingpath string, parts []string) (error, bool, string) { + time.Sleep(10 * time.Second) + return RunCmd(workingpath, parts) +} + +func RunCmd(workingpath string, parts []string) (error, bool, string) { + 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) + if thing == "pwd" { + os.Exit(-1) + } + // 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 +} |
