ariya/phantomjs — pull request #181 by TriggeredMessaging (2011-12-02 12:05:26+00:00)
Title: implement getStdinLine

I need to create a long-running PhantomJS process to handle rendering of HTML pages to images for our application. My first attempt was to use the fs module. However, fs.read('/dev/stdin','r') doesn't ever return. For example, this just waits for input forever, and doesn't echo anything:

var fs = require('fs');
input = fs.read('/dev/stdin', 'r');
console.log(input);

My patch, in this pull request, implements getStdinLine

So for example, this works correctly and echoes what you typed:
var input = getStdinLine();
console.log(input);

My code was heavily influenced by https://github.com/ariya/phantomjs/pull/46/

If there is a better way to fit this in to PhantomJS, please advise.