在 Node.js 中查找 GPU 信息(型号)
Finding GPU information (model) in Node.js
在Node.js中,我们可以方便的使用os
模块(documentation)来获取CPU信息:
os.cpus()[0].model; // → Example: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz'
我正在寻找一种类似的方法来获取 GPU 型号,如果可能的话,还有规格。
在此先感谢您的帮助!
可以写一个切换os.platform()的模块,然后对每个os执行一个命令来抓取GPU信息,如下:
// Mac OS:
system_profiler | grep GeForce
// Windows:
wmic path win32_VideoController get name
// Linux:
sudo lshw -C display
目前无法从 Node 的 os 对象中获取 GPU 信息os。 possible 解决方案将执行命令 system_profiler SPDisplaysDataType.
在上下文中,这将如下所示:
const { exec } = require("child_process");
exec("system_profiler SPDisplaysDataType", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
// Normalise the result here to get the GPU name
console.log(`stdout: ${stdout}`);
});
});
注意:这是专门针对Mac或darwin平台的
在Node.js中,我们可以方便的使用os
模块(documentation)来获取CPU信息:
os.cpus()[0].model; // → Example: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz'
我正在寻找一种类似的方法来获取 GPU 型号,如果可能的话,还有规格。
在此先感谢您的帮助!
可以写一个切换os.platform()的模块,然后对每个os执行一个命令来抓取GPU信息,如下:
// Mac OS:
system_profiler | grep GeForce
// Windows:
wmic path win32_VideoController get name
// Linux:
sudo lshw -C display
目前无法从 Node 的 os 对象中获取 GPU 信息os。 possible 解决方案将执行命令 system_profiler SPDisplaysDataType.
在上下文中,这将如下所示:
const { exec } = require("child_process");
exec("system_profiler SPDisplaysDataType", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
// Normalise the result here to get the GPU name
console.log(`stdout: ${stdout}`);
});
});
注意:这是专门针对Mac或darwin平台的