start fixing all this old junk

This commit is contained in:
Jeff Carr 2024-03-01 21:45:30 -06:00
parent df45549558
commit 1ff1045445
2 changed files with 27 additions and 9 deletions

21
run.go
View File

@ -47,22 +47,25 @@ func RunString(args string) bool {
func Run(args []string) bool { func Run(args []string) bool {
dir, err := os.Getwd() dir, err := os.Getwd()
if err != nil { if err != nil {
println("Failed to get current directory:", err)
return false return false
} }
return RunPath(dir, args) err = RunPath(dir, args)
if err == nil {
return true
} }
return false
}
var ErrorArgvEmpty error = errors.New("command was empty")
// run, but set the working path // run, but set the working path
func RunPath(path string, args []string) bool { func RunPath(path string, args []string) error {
if len(args) == 0 { if len(args) == 0 {
log.Warn("command line was empty") return ErrorArgvEmpty
return false
} }
if args[0] == "" { if args[0] == "" {
log.Warn("command line was empty") return ErrorArgvEmpty
return false
} }
thing := args[0] thing := args[0]
parts := args[1:] parts := args[1:]
@ -81,9 +84,9 @@ func RunPath(path string, args []string) bool {
log.Info("path =", path) log.Info("path =", path)
log.Info("args =", args) log.Info("args =", args)
log.Info("err =", err.Error()) log.Info("err =", err.Error())
return false return err
} }
return true return nil
} }
func (cmd *OldShell) Run(cmdline string) string { func (cmd *OldShell) Run(cmdline string) string {

View File

@ -165,6 +165,21 @@ func Exec(cmdline string) {
os.Exit(0) os.Exit(0)
} }
func NewRun(workingpath string, cmd []string) error {
log.Log(INFO, "NewRun() ", cmd)
process := exec.Command(cmd[0], cmd[1:len(cmd)]...)
// Set the working directory
process.Dir = workingpath
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 err
}
// return true if the filename exists (cross-platform) // return true if the filename exists (cross-platform)
func Exists(filename string) bool { func Exists(filename string) bool {
_, err := os.Stat(Path(filename)) _, err := os.Stat(Path(filename))