Created
August 12, 2011 14:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec; | |
child = exec('python cpus.py', | |
function (error, stdout, stderr) { | |
console.log(stdout); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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