mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
Merge pull request #256 from shirou/change-platform-version-on-darwin
[host]darwin: change to use sw_vers to get platform version
This commit is contained in:
commit
214acac9ea
@ -32,11 +32,11 @@ func Info() (*InfoStat, error) {
|
||||
ret.Hostname = hostname
|
||||
}
|
||||
|
||||
platform, family, version, err := PlatformInformation()
|
||||
platform, family, pver, version, err := PlatformInformation()
|
||||
if err == nil {
|
||||
ret.Platform = platform
|
||||
ret.PlatformFamily = family
|
||||
ret.PlatformVersion = version
|
||||
ret.PlatformVersion = pver
|
||||
ret.KernelVersion = version
|
||||
}
|
||||
|
||||
@ -135,26 +135,37 @@ func Users() ([]UserStat, error) {
|
||||
|
||||
}
|
||||
|
||||
func PlatformInformation() (string, string, string, error) {
|
||||
func PlatformInformation() (string, string, string, string, error) {
|
||||
platform := ""
|
||||
family := ""
|
||||
version := ""
|
||||
pver := ""
|
||||
|
||||
sw_vers, err := exec.LookPath("sw_vers")
|
||||
if err != nil {
|
||||
return "", "", "", "", err
|
||||
}
|
||||
uname, err := exec.LookPath("uname")
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
return "", "", "", "", err
|
||||
}
|
||||
|
||||
out, err := invoke.Command(uname, "-s")
|
||||
if err == nil {
|
||||
platform = strings.ToLower(strings.TrimSpace(string(out)))
|
||||
}
|
||||
|
||||
out, err = invoke.Command(sw_vers, "-productVersion")
|
||||
if err == nil {
|
||||
pver = strings.ToLower(strings.TrimSpace(string(out)))
|
||||
}
|
||||
|
||||
out, err = invoke.Command(uname, "-r")
|
||||
if err == nil {
|
||||
version = strings.ToLower(strings.TrimSpace(string(out)))
|
||||
}
|
||||
|
||||
return platform, family, version, nil
|
||||
return platform, family, pver, version, nil
|
||||
}
|
||||
|
||||
func Virtualization() (string, string, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user