获取系统版本
()
| 70 | |
| 71 | // 获取系统版本 |
| 72 | func getOsInformation() string { |
| 73 | var execCommand *exec.Cmd |
| 74 | |
| 75 | output := runtime.GOOS + " " + runtime.GOARCH |
| 76 | |
| 77 | switch runtime.GOOS { |
| 78 | case "windows": |
| 79 | |
| 80 | execCommand = exec.Command("powershell", "/c", "Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption") |
| 81 | outputBytes, err := execCommand.Output() |
| 82 | |
| 83 | if err == nil { |
| 84 | |
| 85 | decodeBytes, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(outputBytes) |
| 86 | output = string(decodeBytes) |
| 87 | } |
| 88 | |
| 89 | case "darwin": |
| 90 | |
| 91 | execCommand = exec.Command("bash", "-c", "sw_vers") |
| 92 | outputBytes, err := execCommand.Output() |
| 93 | if err == nil { |
| 94 | tmp := string(outputBytes) |
| 95 | productName := "" |
| 96 | productVersion := "" |
| 97 | for _, str := range strings.Split(tmp, "\n") { |
| 98 | if strings.Contains(strings.ToLower(str), "productname") { |
| 99 | productName = strings.ReplaceAll(strings.Split(str, ":")[1], "\t", "") |
| 100 | } else if strings.Contains(strings.ToLower(str), "productversion") { |
| 101 | productVersion = strings.ReplaceAll(strings.Split(str, ":")[1], "\t", "") |
| 102 | } |
| 103 | } |
| 104 | output = productName + "\t" + productVersion |
| 105 | } |
| 106 | |
| 107 | case "linux": |
| 108 | |
| 109 | execCommand = exec.Command("bash", "-c", "lsb_release -a") |
| 110 | outputBytes, err := execCommand.Output() |
| 111 | if err == nil { |
| 112 | tmp := string(outputBytes) |
| 113 | for _, str := range strings.Split(tmp, "\n") { |
| 114 | if strings.Contains(strings.ToLower(str), "description") { |
| 115 | output = strings.ReplaceAll(strings.Split(str, ":")[1], "\t", "") |
| 116 | break |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | default: |
| 122 | |
| 123 | } |
| 124 | |
| 125 | //output = strings.ReplaceAll(output, "\t", "") |
| 126 | |
| 127 | return output |
| 128 | |
| 129 | } |