return output instead of printing it

This commit is contained in:
Greg Gauthier 2021-03-08 21:27:15 +00:00
parent f4fb881377
commit 64431969ad

View File

@ -15,7 +15,7 @@ func validateos() {
} }
} }
func execute(cmdstr string) { func execute(cmdstr string) string {
validateos() validateos()
@ -23,17 +23,17 @@ func execute(cmdstr string) {
var cmd = cmdargs[0] // command var cmd = cmdargs[0] // command
cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd
out, err := exec.Command(cmd, cmdargs...).CombinedOutput() out, err := exec.Command(cmd, cmdargs...).CombinedOutput()
var output string
if err != nil { if err != nil {
fmt.Println(err) output = err.Error()
} else {
output = string(out[:])
} }
output := string(out[:]) return output
fmt.Println(output)
} }
func main() { func main() {
execute("lsof -iTCP -sTCP:LISTEN -P") gitver := execute("git --version")
execute("gcc --version") fmt.Println(gitver)
execute("java -version")
execute("python3 --version")
execute("php --version")
} }