Merge pull request #2627 from dgageot/2626-windows-version-non-english

FIX #2626 Retrieve windows version on non-english OS
This commit is contained in:
Nathan LeClaire 2015-12-18 16:16:41 -08:00
commit ecfe9a18bf
2 changed files with 7 additions and 16 deletions

View File

@ -6,7 +6,7 @@ import (
)
func LocalOSVersion() string {
command := exec.Command(`systeminfo`)
command := exec.Command(`ver`)
output, err := command.Output()
if err != nil {
return ""
@ -15,11 +15,5 @@ func LocalOSVersion() string {
}
func parseOutput(output string) string {
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.HasPrefix(line, "OS Version") {
return strings.TrimSpace(line[len("OS Version:"):])
}
}
return ""
return strings.TrimSpace(output)
}

View File

@ -8,13 +8,10 @@ import (
func TestOSWindows(t *testing.T) {
output := `
Host Name: DESKTOP-3A5PULA
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.10240 N/A Build 10240
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: Windows User
Microsoft Windows [version 6.3.9600]
`
assert.Equal(t, "10.0.10240 N/A Build 10240", parseOutput(output))
assert.Equal(t, "Microsoft Windows [version 6.3.9600]", parseOutput(output))
}