duanjiuhong5843 2019-07-15 10:57
浏览 59

检测操作系统版本

The runtime package can return the operating system. This is great because someone can just call runtime.GOOS which will return on of:

const GOOS = `windows`
const GoosAix = 0
const GoosAndroid = 0
const GoosDarwin = 0
const GoosDragonfly = 0
const GoosFreebsd = 0
const GoosHurd = 0
const GoosJs = 0
const GoosLinux = 0
const GoosNacl = 0
const GoosNetbsd = 0
const GoosOpenbsd = 0
const GoosPlan9 = 0
const GoosSolaris = 0
const GoosWindows = 1
const GoosZos = 0

There are some use case where this is not enough and users want to detect the specific version and just the OS family. How to detect the version of the operating system?

From the command line someone can type:

sw_vers on macOS

ProductName: Mac OS X

ProductVersion: 10.14.5

BuildVersion: 18F132

lsb_release -a on Ubuntu

Distributor ID: Ubuntu

Description: Ubuntu 14.04.5 LTS

Release: 14.04

Codename: trusty

ver on Windows

Microsoft Windows [Version 10.0.17134.829]

I guess this can be done by using os/exec and parsing the output of the commands above, but is there a better way?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器