gitee.com/quant1x/gox@v1.21.2/devices/cpu_windows.go (about)

     1  //go:build windows
     2  
     3  package devices
     4  
     5  import (
     6  	"os/exec"
     7  	"regexp"
     8  )
     9  
    10  func CpuPhysicalID() (PhysicalID string, err error) {
    11  	PhysicalID = "Unknown"
    12  	cmd := exec.Command("wmic", "cpu", "get", "ProcessorID")
    13  	out, err := cmd.CombinedOutput()
    14  	if err != nil {
    15  		return
    16  	}
    17  	str := string(out)
    18  	// 匹配一个或多个空白符的正则表达式
    19  	reg := regexp.MustCompile("\\s+")
    20  	str = reg.ReplaceAllString(str, "")
    21  	return str[11:], nil
    22  }