summaryrefslogtreecommitdiff
path: root/exec.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-12 06:35:36 -0600
committerJeff Carr <[email protected]>2025-01-12 06:35:36 -0600
commit1534b9fbbcd883b5820d53c86e4923185574cfe0 (patch)
tree788e72f2954cbd1621dc2cf73b11c0792083d85c /exec.go
parentd5f45aef137c6298b6092e160bd1fb2476b5062f (diff)
shell exec for 'forge commit'v0.22.21
Diffstat (limited to 'exec.go')
-rw-r--r--exec.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/exec.go b/exec.go
new file mode 100644
index 0000000..57b8605
--- /dev/null
+++ b/exec.go
@@ -0,0 +1,48 @@
+package shell
+
+import (
+ "errors"
+ "os"
+ "os/exec"
+
+ "go.wit.com/log"
+)
+
+func Exec(args []string) error {
+ if len(args) == 0 {
+ return errors.New("Error: Command slice is empty.")
+ }
+
+ // Start a long-running process, capture stdout and stderr
+ a, b := RemoveFirstElement(args)
+
+ process := exec.Command(a, b...)
+ process.Stderr = os.Stderr
+ process.Stdin = os.Stdin
+ process.Stdout = os.Stdout
+ process.Start()
+ err := process.Wait()
+ log.Log(INFO, "shell.Exec() err =", err)
+ return nil
+}
+
+func ExecCheck(args []string) error {
+ if len(args) == 0 {
+ return errors.New("Error: Command slice is empty.")
+ }
+
+ // Start a long-running process, capture stdout and stderr
+ a, b := RemoveFirstElement(args)
+
+ process := exec.Command(a, b...)
+ process.Stderr = os.Stderr
+ process.Stdin = os.Stdin
+ process.Stdout = os.Stdout
+ err := process.Run()
+ if err != nil {
+ log.Info("ExecCheck() err", err)
+ return err
+ }
+ log.Info("ExecCheck() nil")
+ return nil
+}