go-learn/check-versions.go

40 lines
758 B
Go
Raw Normal View History

2021-03-08 17:50:01 +00:00
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
)
func validateos() {
if runtime.GOOS == "windows" {
fmt.Println("Can't Execute this on a windows machine")
os.Exit(1)
}
}
func execute(cmdstr string) {
validateos()
var cmdargs = strings.Split(cmdstr, " ") // string arrayified
var cmd = cmdargs[0] // command
cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd
out, err := exec.Command(cmd, cmdargs...).CombinedOutput()
if err != nil {
fmt.Println(err)
}
output := string(out[:])
fmt.Println(output)
}
func main() {
2021-03-08 20:09:39 +00:00
execute("lsof -iTCP -sTCP:LISTEN -P")
2021-03-08 17:50:01 +00:00
execute("gcc --version")
execute("java -version")
execute("python3 --version")
execute("php --version")
}