Skip to content

Instantly share code, notes, and snippets.

@clarkmcc
Created March 5, 2020 17:56
Show Gist options
  • Save clarkmcc/39174701aba1e38fbaaf0dc1e17b7e66 to your computer and use it in GitHub Desktop.
Save clarkmcc/39174701aba1e38fbaaf0dc1e17b7e66 to your computer and use it in GitHub Desktop.
Golang function to determine whether a windows machine is 32 bit or 64 bit.
func GetArch() (string, *errors.ErrorCode) {
cmd := exec.Command(
"wmic",
"os",
"get",
"osarchitecture",
)
output, err := cmd.CombinedOutput()
if err != nil {
return "", errors.New(errors.UnsupportedArchitecture)
}
is64 := strings.Index(string(output), "64")
is32 := strings.Index(string(output), "32")
if is32 < 0 && is64 < 0 {
return "", errors.New(errors.UnsupportedArchitecture)
}
if is32 >= 0 {
return "32", nil
} else if is64 >= 0 {
return "64", nil
}
return "", errors.New(errors.UnsupportedArchitecture)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment