From 64431969ad0f950744d21befc5a6b72f3ab295b4 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Mon, 8 Mar 2021 21:27:15 +0000 Subject: [PATCH] return output instead of printing it --- check-versions.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/check-versions.go b/check-versions.go index 33fe54b..15754df 100644 --- a/check-versions.go +++ b/check-versions.go @@ -15,7 +15,7 @@ func validateos() { } } -func execute(cmdstr string) { +func execute(cmdstr string) string { validateos() @@ -23,17 +23,17 @@ func execute(cmdstr string) { var cmd = cmdargs[0] // command cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd out, err := exec.Command(cmd, cmdargs...).CombinedOutput() + var output string + if err != nil { - fmt.Println(err) + output = err.Error() + } else { + output = string(out[:]) } - output := string(out[:]) - fmt.Println(output) + return output } func main() { - execute("lsof -iTCP -sTCP:LISTEN -P") - execute("gcc --version") - execute("java -version") - execute("python3 --version") - execute("php --version") + gitver := execute("git --version") + fmt.Println(gitver) }