var page = require('webpage').create();
var _ = require('underscore');
var fs = require('fs');

function stdout(str) {
  fs.write('/dev/stdout', str, 'w')
}

function stderr(str) {
  fs.write('/dev/stderr', str, 'w')
}

page.onAlert = stdout;
page.onConsoleMessage = stdout;
page.onError = stderr;

page.onLoadFinished = function() {
  phantom.exit();
};

page.open(phantom.args[0]);

@@ -68,18 +68,22 @@
 ');%0Avar 
-f
 s
+ystem
  = requi
@@ -90,215 +90,134 @@
 re('
-fs');%0A%0Afunction stdout(str) %7B%0A  fs.write('/dev/stdout', str, 'w')%0A%7D%0A%0Afunction stderr(str) %7B%0A  fs.write('/dev/stderr', str, 'w')%0A%7D%0A%0Apage.onAlert = stdout;%0Apage.onConsoleMessage = stdout;%0Apage.onError = stderr
+system');%0A%0Apage.onAlert = system.stdout.write;%0Apage.onConsoleMessage = system.stdout.write;%0Apage.onError = system.stderr.write
 ;%0A%0Ap
@@ -265,16 +265,17 @@
 om.exit(
+0
 );%0A%7D;%0A%0Ap

Use `system` module for phantom runner script stdout/stderr