Read the statement by Michael Teeuw here.
python script into MagicMirror module
-
Hi, I want to run the python script into MagicMirror module. Kindly give the solution to my requirement.
-
@sureshkocherla
You can execute an external program withChild Processofnode.js. After reading this, create or modify your module.
https://nodejs.org/api/child_process.html -
Hi, Sean Thanks for your valuable reply,
I have one python script. I want to create a new custom module for the requirement and also run this python script automatically in the module.
Kindly guide me. -
@sureshkocherla
Ok, Let’s see the example.
MMM-Toolsis using several external shell scripts in the module.
https://github.com/eouia/MMM-ToolsSee the
node_helpers.js(https://github.com/eouia/MMM-Tools/blob/master/node_helper.js)
First, Child process could not be used on the frontend, so you need to buildnode_helpers.jsfor it.in line 10
var exec = require('child_process').execchild_proces.exec is declared to use. You might need other methods like
spawnorforkfor your purpose.in line 123.
getIP : function() { exec (this.scripts['IP'], (err, stdout, stderr)=>{ if (err == null) { var matched = stdout.trim().match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) this.status['IP'] = (matched) ? matched[0] : "Unknown" } }) },this is all for your using
exec.exec ("your command", function callback(error, outputonsuccess, outputonerr) { console.log(error, outputonsuccess, outputonerror) })Try this in your module.
※ child_process.exec is a just simple method to get result of external command. But when you need more complexed function, you could consider
spawnorforkorexecFileinsteadexechttps://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node
this doc will be help.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login