From 209074a2448b17dfbd6d92057e4410bc4309830d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Jan 2024 14:21:02 -0600 Subject: strangely time.Sleep() doesn't seem to work Signed-off-by: Jeff Carr --- unix.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'unix.go') diff --git a/unix.go b/unix.go index 5574e5d..f2e27f7 100644 --- a/unix.go +++ b/unix.go @@ -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 +} -- cgit v1.2.3