通过Node.js将任务传递给Python
你好,我打算开发一个内部使用的网页应用,使用的是node.js。这款应用主要是用来批量修复xml文件的。我希望用户只需要上传一个包含所有xml文件的压缩包,应用会处理这些文件,然后再把处理好的文件发送回去让他们下载。请问能不能把这个xml文件的修复工作交给python来做(主要是因为有lxml这个模块)。等python处理完后,它会告诉node.js输出文件的位置,然后node.js再通知用户。
我打算这样做:exec('python fix.py someOptions', callback)
。这种做法会有什么副作用吗?
PS:我现在使用的是windows XP和cygwin。
1 个回答
2
我在Windows XP上用node.js v0.8.18进行了测试(这是官方版本)
var spawn = require('child_process').spawn,
pythonProcess = spawn('python', ['fix.py', 'someOptions']);
pythonProcess.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
pythonProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
pythonProcess.on('close', function (code) {
console.log('child process exited with code ' + code);
});