Is it possible to use node.js to call a perl script as a process and read back stdout line by line?
I pretty sure with normal javascript this is usually not possible but a server side script using node.js it would seem to make some sense.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With