Simple button that triggers an external python script


#1

Hi all,

I want to utilize Meteor for a narrow use-case where the end user has the ability to click a button that will trigger an external Python script and do nothing else (the Python script does not send data back to Meteor). What’s the simplest JavaScript code that can do this? Thanks.


#2

use something like this: https://github.com/extrabacon/python-shell

or a system call. Trigger this from a method (http://docs.meteor.com/api/methods.html)


#3
Meteor.methods({
    myPythonCall: function(value) {
        var exec = Npm.require('child_process').exec;
        var errorCallBack = function(e) { console.log("errorCallBack"); };
        var runCmd = Meteor.wrapAsync(exec,
        Meteor.bindEnvironment(
            function(error, stdout, stderr) {
                if (error)
                    console.log('Error binding to environment');
            },
            errorCallBack
        ) );

        var command = "python foo.py";
        var result = runCmd(command);
        console.log(result);
    }
})

You then call that method through an event listener which is executed through a click on the button.