-
Notifications
You must be signed in to change notification settings - Fork 49
/
goInfo_windows.go
52 lines (48 loc) · 1.14 KB
/
goInfo_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package goInfo
import (
"bytes"
"fmt"
"os"
"os/exec"
"runtime"
"strings"
)
func GetInfo() (GoInfoObject, error) {
cmd := exec.Command("cmd", "ver")
cmd.Stdin = strings.NewReader("some input")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
gio := GoInfoObject{Kernel: "windows", Core: "unknown", Platform: platform(), OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
return gio, fmt.Errorf("getInfo: %s", err)
}
ver := "unknown"
outStr := out.String()
if strings.Contains(outStr, "[") {
parts := strings.Split(strings.ReplaceAll(outStr, "\r\n\t", ""), "[")
if len(parts) >= 2 {
x := parts[1]
x = strings.Split(x, "]")[0]
parts = strings.Split(x, " ")
ver = parts[len(parts)-1]
}
}
gio := GoInfoObject{Kernel: "windows", Core: ver, Platform: platform(), OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname()
return gio, nil
}
func platform() string {
p := runtime.GOARCH
switch p {
case "386":
return "i386"
case "amd64":
return "x86_64"
default:
return p
}
}