Is it possible to start and continue to capture output from a certain bash process with node? For example: say I was run tail /some/file, how can I keep listening to every new line printed and act on the output?
2 Answers
var spawn = require('child_process').spawn,
    tail  = spawn('tail', ['-f', '/tmp/somefile']);
tail.stdout.pipe(process.stdout);
child_process module is well documented
2 Comments
Dominic Barnes
 You can also run 
  exec and it'll gather the entire output of stdout and stderr for you. For an instance like tail that'll work out fine. (If you have a continously running script, monitoring the output streams is a better option)Ahmed Nuaman
 Yep my script is a continous one, for example 
  tail or Google App Engine's dev_appserver.py. I'll test this and get back to you.For completeness, I've added this answer as well.
You can use child_process.spawn to spawn a process and monitor it's output. However, for a command like tail, cat, etc that don't run long or continuously you can just use child_process.exec and it will capture the entire output for stdout and stderr and give it to you all at once.
var cp = require("child_process");
cp.exec("tail /some/file", function (err, stdout, stderr) {
    // If an error occurred, err will contain that error object
    // The output for the command itself is held in stdout and stderr vars
});

child_processmodule. :)