2021-03-16 12:32:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-03-16 23:06:20 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-03-16 12:32:59 +00:00
|
|
|
"os/exec"
|
2024-07-09 20:29:11 +00:00
|
|
|
"runtime"
|
2021-03-16 12:32:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func isInstalled(name string) bool {
|
2024-07-09 20:29:11 +00:00
|
|
|
var cmd *exec.Cmd
|
|
|
|
|
|
|
|
// check for the operating system
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// 'where' command is used on Windows to locate executables
|
|
|
|
cmd = exec.Command("where.exe", name)
|
|
|
|
} else {
|
|
|
|
// 'command' is used on Unix systems
|
|
|
|
cmd = exec.Command("/bin/sh", "-c", "command -v "+name)
|
|
|
|
}
|
|
|
|
|
2021-03-16 12:32:59 +00:00
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:06:20 +00:00
|
|
|
func subExecute(program string, args ...string) ([]byte, error) {
|
|
|
|
cmd := exec.Command(program, args...)
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%v\n", err)
|
|
|
|
}
|
|
|
|
return cmd.CombinedOutput()
|
2021-03-16 12:32:59 +00:00
|
|
|
}
|