How to call Shell script or python script in from a Atom electron app How to call Shell script or python script in from a Atom electron app shell shell

How to call Shell script or python script in from a Atom electron app


It can be done directly with Node, you can use the child_process module. Please notice this is asynchronous.

const exec = require('child_process').exec;function execute(command, callback) {    exec(command, (error, stdout, stderr) => {         callback(stdout);     });};// call the functionexecute('ping -c 4 0.0.0.0', (output) => {    console.log(output);});

I encourage you to also have a look at npm, there are tons of modules that could help you to do what you want, without calling a python script.


Try node-powershell npm. You can directly execute shell script commands and display result.

var shell = require('node-powershell')var ps = new shell()ps.addCommand('ping -c 4 0.0.0.0')ps.invoke().then(function (output) {    console.log(output)}).catch(function (err) {    console.log(err)    ps.dispose()})

See: https://www.npmjs.com/package/node-powershell


you could use child_process to archive what you are trying to do by using the following code

var exec = require('child_process').execfunction Callback(err, stdout, stderr) {    if (err) {        console.log(`exec error: ${err}`);        return;    }else{        console.log(`${stdout}`);    }}res = exec('ping xxx.xxx.xxx', Callback);