updates after 4 years
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
0b634a2a53
commit
c877c3886d
39
run.go
39
run.go
|
@ -22,11 +22,42 @@ var msecDelay int = 20 // check every 20 milliseconds
|
||||||
// exiterr.Sys().(syscall.WaitStatus)
|
// exiterr.Sys().(syscall.WaitStatus)
|
||||||
|
|
||||||
// var newfile *shell.File
|
// var newfile *shell.File
|
||||||
|
func RunString(args string) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func Run(cmdline string) string {
|
func Run(args []string) bool {
|
||||||
test := New()
|
dir, err := os.Getwd()
|
||||||
test.Exec(cmdline)
|
if err != nil {
|
||||||
return Chomp(test.Buffer)
|
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 {
|
func (cmd *Shell) Run(cmdline string) string {
|
||||||
|
|
18
shell.go
18
shell.go
|
@ -56,7 +56,7 @@ func Script(cmds string) int {
|
||||||
line = Chomp(line) // this is like 'chomp' in perl
|
line = Chomp(line) // this is like 'chomp' in perl
|
||||||
log.Log(INFO, "LINE:", line)
|
log.Log(INFO, "LINE:", line)
|
||||||
time.Sleep(1)
|
time.Sleep(1)
|
||||||
Run(line)
|
RunString(line)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func RM(filename string) {
|
||||||
|
|
||||||
func Daemon(cmdline string, timeout time.Duration) int {
|
func Daemon(cmdline string, timeout time.Duration) int {
|
||||||
for {
|
for {
|
||||||
Run(cmdline)
|
RunString(cmdline)
|
||||||
time.Sleep(timeout)
|
time.Sleep(timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,20 @@ func Exists(filename string) bool {
|
||||||
return true
|
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)
|
// return true if the filename exists (cross-platform)
|
||||||
func Dir(dirname string) bool {
|
func Dir(dirname string) bool {
|
||||||
info, err := os.Stat(Path(dirname))
|
info, err := os.Stat(Path(dirname))
|
||||||
|
|
Loading…
Reference in New Issue