Skip to content

Instantly share code, notes, and snippets.

@hdf
Created August 12, 2011 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdf/1142158 to your computer and use it in GitHub Desktop.
Save hdf/1142158 to your computer and use it in GitHub Desktop.
One way to do the currently not functioning os.cpus() in node.js on windows.
var exec = require('child_process').exec;
child = exec('python cpus.py',
function (error, stdout, stderr) {
console.log(stdout);
});
try:
import _winreg as winreg
except ImportError as e:
import winreg
key_path = 'HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\'
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path)
index = 0
s = '['
while True:
try:
winreg.EnumKey(key, index)
sub_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path + str(index))
mhz = winreg.QueryValueEx(sub_key, '~MHz')[0]
model = winreg.QueryValueEx(sub_key, 'ProcessorNameString')[0]
s += '{"model":"' + model + '","speed":' + str(mhz) + ',"times":{}},'
winreg.CloseKey(sub_key)
index += 1
except WindowsError as e:
break
winreg.CloseKey(key)
s = s[0:-1] + ']'
import json
print(json.dumps(json.loads(s), indent = 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment