[英]os.platform() returns darwin instead of OSX
os.platform();
The above JS instruction returns the name of OS . 上面的JS指令返回OS的名称。
When it is runned on Ubuntu , it returns 当它在Ubuntu上运行时,它返回
'linux'
When it is runned on Macbook, it returns 当它在Macbook上运行时,它返回
'darwin'
I am wondered why does not return osx
, unix
or bsd
.. ? 我想知道为什么不返回
osx
, unix
或bsd
..?
Does darwin
is a fork of osx ? darwin
是osx的分支吗?
How to get the type of OS under MAC using Node.js ? 如何使用Node.js获取MAC下的OS类型?
Darwin is not OSX, OSX is Darwin. 达尔文不是OSX,OSX是达尔文。
Darwin is the core of OSX, in the same way, Linux is the core of Debian, Ubuntu, and every other Linux distributions. Darwin是OSX的核心,同样,Linux是Debian,Ubuntu以及其他所有Linux发行版的核心。
So while you can be 100% sure that any Apple product (macOS, OSX, iOS, watchOS, tvOS) will return Darwin, it is technically not correct to assume that darwin will only ever be thoses OSs, since some low profile open source projects exists, like PureDarwin , and thoses would also return darwin
. 因此,虽然你可以100%确定任何Apple产品(macOS,OSX,iOS,watchOS,tvOS)将返回Darwin,但从技术角度来看,假设darwin只会出现操作系统,这是不正确的,因为一些低调的开源项目像PureDarwin一样存在,并且thoses也将返回
darwin
。
However, I do not know of any (officials) port of node.js for any other Darwin-based OSs than OSX, so in practice, yes, if you get darwin
, you can be confident it is OSX. 但是,我不知道node.js的任何(官方)端口对于任何其他基于Darwin的操作系统而不是OSX,所以在实践中,是的,如果你得到
darwin
,你可以确信它是OSX。
Darwin is the underlying platform for OS X. Darwin是OS X的底层平台。
To get the OS X version instead, you can do this via the command line (or child process) with: defaults read loginwindow SystemVersionStampAsString
or sw_vers -productVersion
要获得OS X版本,您可以通过以下命令行(或子进程)执行此操作:
defaults read loginwindow SystemVersionStampAsString
或sw_vers -productVersion
To get the version via C/C++ (which you could write a binding for to access from node): 要通过C / C ++获取版本(您可以编写绑定以便从节点访问):
// compile with: g++ osx_ver.cc -I/Developer/Headers/FlatCarbon -framework CoreServices
#include <Gestalt.h>
#include <stdio.h>
int main() {
SInt32 majorVersion, minorVersion, bugFixVersion;
Gestalt(gestaltSystemVersionMajor, &majorVersion);
Gestalt(gestaltSystemVersionMinor, &minorVersion);
Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);
printf("%d.%d.%d", majorVersion, minorVersion, bugFixVersion);
return 0;
}
Note: The Gestalt()
usage shown above is deprecated since OS X 10.8, but its replacement seemingly isn't available until OS X 10.10, so you may need to use Objective-C instead ( [processInfo operatingSystemVersion]
) and branch on API availability like what is done here in Chromium. 注意:从OS X 10.8开始,上面显示的
Gestalt()
用法已被弃用,但它的替换似乎在OS X 10.10之前不可用,因此您可能需要使用Objective-C( [processInfo operatingSystemVersion]
)并分支API可用性就像Chromium 在这里所做的一样。
Darwin was the original name given to OS X by apple. 达尔文是苹果给OS X的原始名称。 It was named as such because it was the NeXT step in the evolution of operating systems.
之所以如此,是因为它是操作系统发展中的NeXT步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.