Node.js获取/确定操作系统版本 [英] Node.js to get/determine OS version

查看:94
本文介绍了Node.js获取/确定操作系统版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定正在执行的某些脚本是否正在运行特定版本的Mac OSX.我意识到我可以执行/产生命令:

  sw_vers -productVersion 

是否有一种方法可以同步执行此操作(类似于process.arch),而无需 node-exec-同步?我意识到同步生成/执行它是一个公认的坏习惯,但是我看不到另一种方法.

解决方案

您可以使用操作系统模块像这样:

  var os = require('os');os.platform();//'darwin'os.release();//'10.8.0' 

,然后将发行版本映射到Mac OS X的特定版本.

可以在此处 找到达尔文到Mac OS X的映射>

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_vers -productVersion

Is there a way to do this synchronously (similar to process.arch) without node-exec-sync? I realize its an accepted bad practice to spawn/exec synchronously, but I don't see another way.

解决方案

you could use the OS module like this:

var os = require('os');
os.platform(); // 'darwin'
os.release(); //'10.8.0'

and then map the release version to a specific version of Mac OS X.

Darwin to Mac OS X mappings can be found here

这篇关于Node.js获取/确定操作系统版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆