简体   繁体   English

os.platform()返回darwin而不是OSX

[英]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 .. ? 我想知道为什么不返回osxunixbsd ..?

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 SystemVersionStampAsStringsw_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.

相关问题 os.platform 返回浏览器而不是实际的操作系统 - React &amp; Electron - os.platform returns browser instead of actual OS - React & Electron fsevents@2.3.2 不受支持的平台:github 上需要 {"os":"darwin","arch":"any"}(当前:{"os":"linux","arch":"x64"})动作 - Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) on github actions 如何修复 fsevents@2.1.3 不支持的平台:想要 {“os”:“darwin”,“arch”:“any”}(当前:{“os”:“win32”,“arch”:“x64”} ) - how to fix Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”}) 跳过可选依赖:fsevents@1.2.9 不支持的平台:想要 {“os”:“darwin”,“arch”:“any”}(当前:{“os”:“win32”,“arch”:“x64” }) - SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”}) “darwin-arm64v8”二进制文件不能在“darwin-x64”平台上使用 - 'darwin-arm64v8' binaries cannot be used on the 'darwin-x64' platform 未找到平台=darwin arch=arm64 runtime=electron abi=103 的本机构建 - No native build was found for platform=darwin arch=arm64 runtime=electron abi=103 错误:darwin-x64' 二进制文件不能在 'linux-x64' 平台上使用(AWS lambda + typescript + webpack 锐模块) - Error: darwin-x64' binaries cannot be used on the 'linux-x64' platform (AWS lambda + typescript + webpack sharp module ) 无法在此OS上构建平台ios的应用程序 - Applications for platform ios can not be built on this OS NPM安装错误达尔文 - npm install error darwin 跨平台(包括Windows)使用带有nodejs的OS可信证书的方式 - Cross platform (including Windows) way to use OS trusted certificates with nodejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM