简体   繁体   English

通过node.js将任务传递给python

[英]pass a task to python via node.js

Hi I'm planning to develop a webapp in node.js internally used for our company. 嗨,我打算在我们公司内部使用的node.js中开发一个webapp。 The app will mostly do bulk xml file fixing task. 该应用程序将主要执行批量xml文件修复任务。 I wanted my users to just upload a zip file containing all the xml file the app will process it and sends it back to them for download. 我希望我的用户只需上传一个包含应用程序将处理它的所有xml文件的zip文件,然后将其发送回给他们下载。 Is it possible to pass this xml file fixing task to python (mainly because of lxml module). 是否可以将此xml文件修复任务传递给python(主要是因为lxml模块)。 After python is done with the task it will tell node.js the location of the output then node.js will inform the users. 在python完成任务后,它将告诉node.js输出的位置,然后node.js将通知用户。

I'm planning to do it like this exec('python fix.py someOptions', callback) . 我打算像这个exec('python fix.py someOptions', callback) Are there any side-effect with that approach? 这种方法有副作用吗?

PS: I am using windows XP with cygwin PS:我正在使用带有cygwin的Windows XP

I've tested this with node.js v0.8.18 on Windows XP (official binary) 我已在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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM