Node.js to get/determine OS version

前端 未结 2 790
有刺的猬
有刺的猬 2020-12-20 12:36

I\'d like to determine whether some script that is being executed is running a particular version of Mac OSX. I realize I can exec/spawn the command:

sw_ver         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 12:51

    As mentioned above in AndyD's answer's comments, os.release() returns the kernel version. If you want to get the same version number that a user sees in the "About this Mac" UI, you can read and parse out /System/Library/CoreServices/SystemVersion.plist, like so:

    const plist = require('plist');
    let versionInfo = plist.parseFileSync('/System/Library/CoreServices/SystemVersion.plist');
    console.log(JSON.stringify(versionInfo));
    

    https://github.com/kevinsawicki/node-plist

提交回复
热议问题