Skip to content

Instantly share code, notes, and snippets.

View benbuckman's full-sized avatar

Ben Buckman benbuckman

View GitHub Profile
@benbuckman
benbuckman / intercept-stdout.js
Created May 20, 2012 15:42 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
var _ = require('underscore'),
util = require('util');
// intercept stdout, passes thru callback
// also pass console.error thru stdout so it goes to callback too
// (stdout.write and stderr.write are both refs to the same stream.write function)
// returns an unhook() function, call when done intercepting
module.exports = function interceptStdout(callback) {
var old_stdout_write = process.stdout.write,
old_console_error = console.error;