如何从Atom电子应用程序调用Shell脚本或python脚本 [英] How to call Shell script or python script in from a Atom electron app

查看:196
本文介绍了如何从Atom电子应用程序调用Shell脚本或python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use the Atom electron to write a Desktop App for both Mac and Windows.

我需要的是:

一个按钮。

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

And when the user click the button it runs the following shell (or python script):

ping x.x.x.x

结果将显示在TextArea中。

And the result will be displayed in a TextArea.

我试图使用[shelljs]和[yargs],但似乎它对Atom电子不起作用。

I tried to use [shelljs] and [yargs] but it seems like it is not workable with Atom electron.

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

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

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

Any suggestion will be appreciated, thanks :)

推荐答案

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

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 function
execute('ping -c 4 0.0.0.0', (output) => {
    console.log(output);
});

我建议您也看看 npm ,有很多模块可以帮助你做你想做的事情,而无需调用python脚本。

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.

这篇关于如何从Atom电子应用程序调用Shell脚本或python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆