如何从Atom电子应用程序调用Shell脚本或Python脚本

我正在尝试使用Atom电子为Mac和Windows编写桌面应用程序。

我需要的是:

一个button。

而当用户点击button时,它会运行以下shell(或python脚本):

ping xxxx 

结果将显示在TextArea中。

我尝试使用[shelljs]和[yargs],但它似乎不适用于Atom电子。

我想要的只是使用JAVASCRIPT编写桌面应用程序(当然GUI),它调用一些脚本(shell && python)来做一些自动化工作。

任何build议将不胜感激,谢谢:)

它可以直接用Node完成,可以使用child_process模块。 请注意这是asynchronous的。

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

我鼓励你也看看npm ,有很多模块可以帮你做你想做的事情,而不用调用python脚本。

试试node-powershell npm。 您可以直接执行shell脚本命令并显示结果。

 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() }) 

请参阅: https : //www.npmjs.com/package/node-powershell