lib/capcon.js
function hook(stream, opts, exec) {
  var args = _shift(opts, exec);

  opts = args[0];
  exec = args[1];

  var old_write = stream.write;

  stream.write = (function override(stream, writer) {
    return function write(string, encoding, fd) {
      exec(string, encoding, fd);

      if (!opts['quiet']) {
        writer.apply(stream, [ string, encoding, fd ]);
      }
    }
  })(stream, stream.write);

  return function unhook() {
    stream.write = old_write;
    return true;
  }
}
function hook(stream, opts, exec) {
  var args = _shift(opts, exec);

  opts = args[0];
  exec = args[1];

  var old_write = stream.write;

  stream.write = (function override(stream, writer) {
    return function write(string, encoding, fd) {
      exec(string, encoding, fd);

      if (!opts['quiet']) {
        writer.apply(stream, [ string, encoding, fd ]);
      }
    }
  })(stream, stream.write);

  return function unhook() {
    stream.write = old_write;
    return true;
  }
}
Listens to a provided stream, and executes the provided
function for every write call. Accepts options to silence
the output going to the console.

Returns a function to call when you wish to stop listening
to the call.

@param stream a stream to listen on.
@param opts to set flags on the capture.
@param exec the function to call with the output.
@returns {Function}