summaryrefslogtreecommitdiff
path: root/unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'unix.go')
-rw-r--r--unix.go49
1 files changed, 48 insertions, 1 deletions
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
+}