如何使用Node.js获取Windows版本? [英] How to get Windows version using Node.js?

查看:571
本文介绍了如何使用Node.js获取Windows版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Stack Overflow上有关于操作系统版本的问题,但有关于Windows名称的问题,我正在寻找使用Node.js找出Windows名称的问题.

There are questions about OS version on the Stack Overflow but not about the Windows name, I am looking to find out Windows name using Node.js.

我研究了很多模块,例如osplatformgetos并使用process等.发现这些模块有助于获取操作系统说明,进程环境等.我能够获得它也是Linux或Windows,即我正在使用哪个平台.

I have looked into so many modules like os, platform, getos and using process etc. and found that these are helpful to get operating system description, process environment etc. I am able to get it is Linux or Windows too i.e. which platform I am using.

但是,如何检查使用Node.js在系统上安装的是Windows 7还是Windows 7?

But, how can I check, is it Windows 7 or 8 which is installed on my system using Node.js?

我正在Node.js项目中使用kinect2模块,该模块在Windows 8上可以正常运行,但是我希望在Windows 7上使用它.

I am using kinect2 module in my Node.js project which is working fine on Windows 8 but I am looking to use it on Windows 7.

我已检查Kinect2在Windows 7上不起作用.

I have checked that Kinect2 will not work with Windows 7.

推荐答案

您可以使用ver从命令行中找到Windows版本.例如,在我的机器上:

You can find the Windows version from the command line using ver. For example, on my machine:

>  ver

Microsoft Windows [Version 10.0.14393]

要从节点执行此操作,请使用child_process.execSync方法:

To execute this from node, use the child_process.execSync method:

var versionString = require('child_process').execSync('ver').toString().trim()

整个.toString().trim()业务是因为该命令的原始输出以Buffer的形式返回,并在开始和结束处添加了换行符.

The whole .toString().trim() business is because the raw output from the command comes back as a Buffer, with newlines at the beginning and end.

这篇关于如何使用Node.js获取Windows版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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