summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--run.go39
-rw-r--r--shell.go18
2 files changed, 51 insertions, 6 deletions
diff --git a/run.go b/run.go
index ed35653..ed62f61 100644
--- a/run.go
+++ b/run.go
@@ -22,11 +22,42 @@ var msecDelay int = 20 // check every 20 milliseconds
// exiterr.Sys().(syscall.WaitStatus)
// var newfile *shell.File
+func RunString(args string) bool {
+ return false
+}
+
+func Run(args []string) bool {
+ dir, err := os.Getwd()
+ if err != nil {
+ println("Failed to get current directory:", err)
+ return false
+ }
-func Run(cmdline string) string {
- test := New()
- test.Exec(cmdline)
- return Chomp(test.Buffer)
+ return RunPath(dir, args)
+}
+
+func RunPath(path string, args []string) bool {
+ if len(args) == 0 {
+ log.Warn("command line was empty")
+ return false
+ }
+ if args[0] == "" {
+ log.Warn("command line was empty")
+ return false
+ }
+ thing := args[0]
+ parts := args[1:]
+ cmd := exec.Command(thing, parts...)
+ cmd.Dir = path
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ println("path =", path, "cmd =", strings.Join(args, " "))
+ if err := cmd.Run(); err != nil {
+ // Handle error if the command execution fails
+ println("Error executing command:", err.Error())
+ return false
+ }
+ return true
}
func (cmd *Shell) Run(cmdline string) string {
diff --git a/shell.go b/shell.go
index 0ca2de3..6b4d1a2 100644
--- a/shell.go
+++ b/shell.go
@@ -56,7 +56,7 @@ func Script(cmds string) int {
line = Chomp(line) // this is like 'chomp' in perl
log.Log(INFO, "LINE:", line)
time.Sleep(1)
- Run(line)
+ RunString(line)
}
return 0
}
@@ -102,7 +102,7 @@ func RM(filename string) {
func Daemon(cmdline string, timeout time.Duration) int {
for {
- Run(cmdline)
+ RunString(cmdline)
time.Sleep(timeout)
}
}
@@ -174,6 +174,20 @@ func Exists(filename string) bool {
return true
}
+// makes the directory
+func Mkdir(dir string) bool {
+ if Dir(dir) {
+ // already a dir
+ return true
+ }
+ if Exists(dir) {
+ // something else is there
+ return false
+ }
+ Run([]string{"mkdir", "-p", dir})
+ return true
+}
+
// return true if the filename exists (cross-platform)
func Dir(dirname string) bool {
info, err := os.Stat(Path(dirname))