如何从 Atom 电子应用程序调用 Shell 脚本或 python 脚本
How to call Shell script or python script in from a Atom electron app
我正在尝试使用Atom电子为Mac和Windows编写桌面应用程序。
我在这里需要的是:
一个按钮。
当用户单击该按钮时,它将运行以下shell(或python脚本):
ping x.x.x.x
结果将显示在文本区域中。
我尝试使用[shelljs]和[yargs],但似乎它不适用于原子电子。
我想要的只是使用JAVASCRIPT编写桌面应用程序(当然使用GUI),调用一些脚本(shell&& python)来完成一些自动化工作。
任何建议将不胜感激,谢谢:)
可以直接
用 Node 完成,可以使用 child_process
模块。请注意,这是异步的。
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脚本。
试试 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
您可以使用child_process使用以下代码来存档您尝试执行的操作
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);
相关文章:
- 将标志从Node/Express应用程序Python shell传递到Python脚本
- 从shell脚本中杀死Node.js程序
- 从shell脚本向js脚本传递变量
- 如何从 php 调用 shell 脚本
- 使用JavaScript调用Shell脚本以实现自动化
- MongoDB,为 mongo shell 创建脚本
- PHP 无法调用 shell 脚本 (js -> php -> sh)
- 使用 node.js (子进程) 运行 shell 脚本
- 如何从 Atom 电子应用程序调用 Shell 脚本或 python 脚本
- 如何使用 shell 脚本文件运行我的节点脚本
- 监视器shell脚本's日志文件
- 当nodejs尝试执行shell脚本时会发生错误
- 如何将javascript变量值传递给生成html/javascript代码的shell脚本
- 如何从JavaScript调用shell脚本
- 如何通过javascript/jquery从网页执行shell脚本,并在字符串中获得其结果
- 在Node.js 0.10.x中调用shell脚本(包括CLI)的同步子进程
- 通过(Java脚本)接口从shell脚本控制Java实例
- Ajax太慢,无法从服务器端响应(shell脚本)
- 将用户输入从NodeJS发送到shell脚本
- 在IntelliJ IDEA中,我如何创建一个键绑定,以当前文件作为参数执行shell脚本