Javascript 如何从Atom electron应用程序中调用Shell脚本或python脚本

Javascript 如何从Atom electron应用程序中调用Shell脚本或python脚本,javascript,python,node.js,shell,electron,Javascript,Python,Node.js,Shell,Electron,我正在尝试使用Atom electron为Mac和Windows编写一个桌面应用程序 我需要的是: 按钮 当用户单击按钮时,它将运行以下shell(或python脚本): 结果将显示在文本区域中 我试着使用[shelljs]和[yargs],但它似乎不适用于原子电子 我只想使用JAVASCRIPT编写桌面应用程序(当然是GUI),调用一些脚本(shell和python)来完成一些自动化工作 任何建议都将不胜感激,谢谢:)可以直接使用Node完成,您可以使用child\u流程模块。请注意,这是异步

我正在尝试使用Atom electron为Mac和Windows编写一个桌面应用程序

我需要的是:

按钮

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

结果将显示在文本区域中

我试着使用[shelljs]和[yargs],但它似乎不适用于原子电子

我只想使用JAVASCRIPT编写桌面应用程序(当然是GUI),调用一些脚本(shell和python)来完成一些自动化工作


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

可以直接使用Node完成,您可以使用
child\u流程
模块。请注意,这是异步的

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

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

Trynode powershellnpm。您可以直接执行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()
})

请参阅:

您可以使用child\u进程来存档您正试图执行的操作,方法是使用以下代码

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);
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);