FIX #2626 Retrieve windows version on non-english OS

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-12-18 16:26:01 +01:00
parent fbf97b7c73
commit 39694f1ab4
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))
}