updates after 4 years

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-10 16:31:19 -06:00
parent 0b634a2a53
commit c877c3886d
2 changed files with 51 additions and 6 deletions

39
run.go
View File

@ -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(cmdline string) string {
test := New()
test.Exec(cmdline)
return Chomp(test.Buffer)
func Run(args []string) bool {
dir, err := os.Getwd()
if err != nil {
println("Failed to get current directory:", err)
return false
}
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 {

View File

@ -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))