【发布时间】:2016-07-18 18:21:33
【问题描述】:
我正在尝试使用子进程在我的 express 服务器中运行我的 python 程序。如果它是普通的 NodeJS,则该方法有效,但它不适用于我的 API 端点。
var spawn = require('child_process').spawn,
a = spawn('python', ['test.py']);
router.get('/test', function(req, res, next) {
a.stdout.on('data', function(data){
console.log(data.toString());
});
a.stdin.write(JSON.stringify("Hello"));
a.stdin.end();
});
python 程序只是打印 hello。
这里有什么问题,我该如何解决。
谢谢!
【问题讨论】:
标签: python node.js express child-process