
参见child_process。这是一个使用的示例
spawn,它允许您在输出数据时写入stdin并从stderr
child_process.exec提供稍短一些的语法来执行命令。
// with express 3.xvar express = require('express'); var app = express();app.use(express.logger('dev'));app.use(express.bodyParser());app.use(app.router);app.post('/upload', function(req, res){ if(req.files.myUpload){ var python = require('child_process').spawn( 'python', // second argument is array of parameters, e.g.: ["/home/me/pythonscript.py" , req.files.myUpload.path , req.files.myUpload.type] ); var output = ""; python.stdout.on('data', function(data){ output += data }); python.on('close', function(pre){ if (pre !== 0) { return res.send(500, pre); } return res.send(200, output); }); } else { res.send(500, 'No file found') }});require('http').createServer(app).listen(3000, function(){ console.log('Listening on 3000');});