From efce5e2fcef78fad898e80266a5068f0a24c785c Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Tue, 3 Oct 2017 09:45:24 +0200 Subject: [PATCH] bugfix cpuTemperature() - parsing values on windows --- CHANGELOG.md | 1 + lib/cpu.js | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad9d585..5cb8d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.30.4 | 2017-10-03 | bugfix `cpuTemperature()` - parsing values on windows | | 3.30.3 | 2017-10-03 | bugfix `cpuTemperature()` - max value on windows | | 3.30.2 | 2017-09-26 | bugfix `networkInterfaces()` - optimized ip6 address selection | | 3.30.1 | 2017-09-21 | bugfix/typo `inetChecksite()` | diff --git a/lib/cpu.js b/lib/cpu.js index 9026f49..8c779fa 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -361,20 +361,15 @@ function cpuTemperature(callback) { resolve(result); } if (_windows) { - exec("wmic /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature /value", function (error, stdout) { + exec("wmic /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature", function (error, stdout) { if (!error) { let sum = 0; - let lines = stdout.trim().split(/\s\s+/); + let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); lines.forEach(function (line) { - // if (line.match('CriticalTripPoint') && result.max === -1) - // result.max = (parseInt(line.split('CriticalTripPoint=')[1]) - 2732) / 10; - // else - if (line.match('CurrentTemperature')) { - let value = (parseInt(line.split('CurrentTemperature=')[1]) - 2732) / 10; - sum = sum + value; - if (value > result.max) result.max = value; - result.cores.push(value); - } + let value = (parseInt(line) - 2732) / 10; + sum = sum + value; + if (value > result.max) result.max = value; + result.cores.push(value); }); if (result.cores.length) { result.main = sum / result.cores.length;