如何在 Koa 中使用 child_process.exec (async/await)
首先安装 child-process-promise 库
install.sh
npm i --save child-process-promise然后你可以像这样使用它:
koa_exec.js
const router = require('koa-router')();
const {exec} = require('child-process-promise');
router.get('/test', async ctx => {
const [stdout, stderr] = await exec('python myscript.py')
const ipv6 = stdout.toString();
ctx.body = ipv6;
});Check out similar posts by category:
Javascript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow