I have an endless command line stream - namely logs from my heroku app - and want to parse it by line into node.js.
I have tried various approaches, like with the readline interface (does nothing):
var command = 'heroku logs --app myapp --tail';
var heroku = Npm.require('child_process').exec(command);
var readline = Npm.require('readline');
var rl = readline.createInterface({
input: heroku.stdin,
output: process.stdout
});
rl.on('line', function(log) {
console.log(log);
});
Or with just raw exec, that does return an initial buffer, but does not read continously from the process:
var command = 'heroku logs --app myapp --tail';
var heroku = Npm.require('child_process').exec(command);
heroku.stdout.setEncoding('utf8');
heroku.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
I did not get it to work with spawn - even though I think it may be correct.
What would be a better approach (I'm using meteor, hence the added Npm).