Read the statement by Michael Teeuw here.
help converting code for module...
-
exec(“YOUR-SHELL-COMMAND”, (error, stdout, stderr)=>{ console.log(stdout) // do your job with `stdout` })
I think you can get the result of any execution of shell script.
-
@sean
Not sure I follow …
what would be my ‘shell command’?
-
@justjim1220
**
PS C:\WINDOWS\system32> get-temperature
**
I don’t know anything about your intention, but ‘get-temperature’ could be executable in your shell or terminal, it could be the one. -
@sean
Yes, that is the command to get the temps from the PC using powershell or command prompt…
BUT, where to use the command in node_helper.js?
OR, where to use the command in the module.js file?
-
@justjim1220 let’s look at the design of your module.
How often do u need to get the temps?
Is it on a timer, or some other mechanism?Anyhow, on that cycle, you would issue the ‘run’ of the powershell app in the node_helper.js, and capture it’s output.
Then process the output, remove all the useless data. Then send the raw data to the module.js, who will then format the HTML in the get_dom() function for display
-
const exec = require('child_process').exec var NodeHelper = require("node_helper") module.exports = NodeHelper.create({ socketNotificationReceived: function(noti, payload) { if (noti == "GIVE_ME_RESULT") { setTimeout(()=>{ exec("C:\WINDOWS\system32\get-temperature", //I don't know WINDOWS system at all. Is it right? (err, sto, ste) => { if (!err) { this.sendSocketNotification("HERE_IS_RESULT", sto) } else { console.log("Error", err) } } ) }, 1000) } } })
It isn’t tested. But you can catch the idea.