繁体   English   中英

在OS X上获取OS版本

[英]Get OS version on OS X

我有一个旧脚本,我用它在Ubuntu中运行。 现在,我有一台Mac并希望重用该脚本。

有谁知道在Mac OS中什么等同于以下命令?

def runCmd(cmd):
    p = subprocess.Popen(cmd,
                         shell=True, 
                         stdin=subprocess.PIPE, 
                         stdout=subprocess.PIPE, 
                         stderr=subprocess.PIPE, 
                         close_fds=True)
    result=p.stdout.readlines()
    s=result[0].split()[0]
    return s

def getKernelVer():
    cmd="uname -r| cut --delim=\'.\' -f1-2"
    return runCmd(cmd)

def getUbuntuVer():
    cmd="lsb_release  -a | grep Release | cut -f 2"
    return runCmd(cmd)

谢谢

uname -r在达尔文下的工作方式相同。 内核版本不是大多数人谈论或关心的东西,但它就在那里。 只有问题是cut不支持--delim long选项,所以,试试这个:

uname -r | cut -d. -f1-2

但是,对于Darwin而言,内核版本控制与Linux完全不同,因此在此处运行cut的目的尚不清楚。 (事实上​​,在Linux上也不是很清楚,因为版本控制方案在版本3.0中发生了显着变化。)

要获得当前版本的Mac OS(大致相当于您为Ubuntu获取的“版本”),您可以使用以下命令:

sw_vers -productVersion

您可以使用python“platform”模块(我无法访问Ubuntu,请尝试并发布您的发现:)

  1. 使用platform.system()来区分Linux或Darwin
  2. 调用platform.release()来获取内核版本
  3. 调用platform.linux_distribution()或platform.mac_ver()以获取供应商特定的版本号。

在CentOS上:

$ python
Python 2.7.5 (default, Jul 23 2013, 17:26:16) 
[GCC 4.7.2 20121015 (Red Hat 4.7.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.32-358.18.1.el6.x86_64'
>>> platform.linux_distribution()
('CentOS', '6.4', 'Final')
>>> 

在OS X上:

$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'13.0.0'
>>> platform.mac_ver()
('10.9', ('', '', ''), 'x86_64')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM