freopen("/dev/tty", "a", stdout);
NOTE: This method will not work with Mountain Lion.
sudo nvram boot-args="iog=0x0"
Then restart the machine should make it work.
To turn the display back on:
Hold down Com+Alt+R+P while rebooting macbook until you hear the booting sound twice.