feat: basic binary execution

This commit is contained in:
2026-03-30 23:16:48 +02:00
parent 5533e87bc9
commit 9b2eefcc52
5 changed files with 115 additions and 29 deletions
+63
View File
@@ -0,0 +1,63 @@
package runner
import (
"log"
"os"
"os/exec"
"runtime"
)
func FindMeshbookBinary() (bool, string) {
var osBin string
switch runtime.GOOS {
case "windows":
osBin = "meshbook.exe"
case "linux":
osBin = "meshbook"
default:
log.Println("undefined operating system")
}
log.Println("going to search for:", osBin)
binaryFound := false
var binaryPath string
for _, f := range []string{("./" + osBin), ("./bin/" + osBin)} {
objInfo, err := os.Stat(f)
if err == nil && objInfo.Mode().IsRegular() {
binaryFound = true
binaryPath = f
log.Printf("found binary at %s", f)
break
}
}
if binaryFound {
return true, binaryPath
} else {
return false, ""
}
}
func RunMeshbook(binPath, bookPath, targGroup string) (bool, string) {
var args []string
if len(bookPath) == 0 {
args = []string{"--help"}
} else {
args = []string{"--nograce", "-mb", bookPath, "--group", targGroup}
}
log.Printf("running with parameters: %v", args)
cmd := exec.Command(binPath, args...)
cOut, err := cmd.CombinedOutput()
if err != nil {
log.Printf("something went wrong when running the command: %v", err)
log.Printf("captured output: %s", string(cOut))
return false, ""
}
log.Printf("captured output: %s", string(cOut))
return true, ""
}