How to call Shell script or python script in Atom application

I am trying to use Atom electron to write a desktop application for Mac and Windows.

I need here:

Button

A.

And when the user clicks the button, he launches the following shell (or python script):

ping xxxx 

And the result will be displayed in TextArea.

I tried to use [shelljs] and [yargs], but it does not seem to work with the Atom atom.

All I want to do is use JAVASCRIPT to write a Desktop App (with a graphical interface, of course) that calls some script (shell && python) to do some automation work.

Any suggestion would be appreciated, thanks :)

+11
source share
4 answers

This can be done directly with Node, you can use the child_process module. Please note that this is asynchronous.

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

I also urge you to take a look at npm , there are many modules here that can help you do what you want without calling a Python script.

+28
source

Try node-Powershell npm. You can directly execute shell script commands and display the 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

+4
source

You can use child_process to archive what you are trying to do using the following code

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

Is there a cross-platform function that executes system shell commands?

0
source

Source: https://habr.com/ru/post/1241785/


All Articles