node.js call a perl script and get stdout
You could use node's built-in spawn
command for child process execution, and carrier
to handle line-by-line processing of stdout
:
Install:
$ npm install carrier
Code:
var util = require('util'),
spawn = require('child_process').spawn,
carrier = require('carrier'),
pl_proc = spawn('perl', ['script.pl']),
my_carrier;
my_carrier = carrier.carry(pl_proc.stdout);
my_carrier.on('line', function(line) {
// Do stuff...
console.log('line: ' + line);
})
Yes, look into spawn/exec.
http://nodejs.org/docs/v0.4.8/api/child_processes.html
var exec = require('child_process').exec;
exec("perl someperl.pl", function(err, stdout, stderr) {
/* do something */
});
I am not sure why you wouldn't just do it in node.