From 1f52d3083efb7768b8d7e21c7b9761c029b62584 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 9 Jan 2024 09:35:54 -0600 Subject: more stuff Signed-off-by: Jeff Carr --- unix.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 unix.go (limited to 'unix.go') diff --git a/unix.go b/unix.go new file mode 100644 index 0000000..94a722f --- /dev/null +++ b/unix.go @@ -0,0 +1,55 @@ +// This is a simple example +package main + +import ( + "os" + "os/exec" + "strings" + + "go.wit.com/log" + +// "go.wit.com/gui/gui" +// "go.wit.com/gui/gadgets" +// "go.wit.com/apps/control-panel-dns/smartwindow" +) + +func fullpath(repo string) string { + return "/home/jcarr/go/src/" + repo +} + +func run(path string, thing string, cmdline string) string { + parts := strings.Split(cmdline, " ") + // Create the command + cmd := exec.Command(thing, parts...) + + // Set the working directory + cmd.Dir = fullpath(path) + + // Execute the command + output, err := cmd.CombinedOutput() + if err != nil { + log.Error(err, "cmd error'd out", parts) + return "" + } + + // Print the output + log.Info(string(output)) + return string(output) +} + +func listFiles(directory string) []string { + var files []string + fileInfo, err := os.ReadDir(directory) + if err != nil { + log.Error(err) + return nil + } + + for _, file := range fileInfo { + if !file.IsDir() { + files = append(files, file.Name()) + } + } + + return files +} -- cgit v1.2.3