standard input and output

601 views
Skip to first unread message

Teemu Ikonen

unread,
May 2, 2012, 7:10:22 AM5/2/12
to phan...@googlegroups.com
Hi,

We needed way to control phantomjs binary by stdin and stdout for using it as queued rendering engine and noticed that reading from /dev/stdin and /dev/stdout with require('fs').open('/dev/stdin').readLine() didn't work as expected and blocked until end of file mark. Also those device files are not available in all platforms. I added stdin, stdout and stderr file objects as standard members to filesystem object, so its possible to do this:

var stdin = require('fs').stdin();

var line;
while( line = stdin.readLine() ) {
   console.log( line );
}

I would like to get this or something similar on the main release, any comments if it's right approach for stdout/stdin or how to improve this?

Thanks, Teemu I.

Milian Wolff

unread,
May 2, 2012, 8:02:10 AM5/2/12
to phan...@googlegroups.com
If I understand this correctly: http://wiki.commonjs.org/wiki/System/1.0

Then these methods should be in the system module.

cheers

Teemu Ikonen

unread,
May 2, 2012, 8:43:21 AM5/2/12
to phan...@googlegroups.com
Good point, I'll move the stdin/err/out as objects in system module

var stdin = require('system').stdin;

var line;
while( line = stdin.readLine() ) {
   console.log( line );
}

/Teemu

Ariya Hidayat

unread,
May 2, 2012, 7:34:22 PM5/2/12
to phan...@googlegroups.com
See also http://code.google.com/p/phantomjs/issues/detail?id=333 (and
the linked pull request). It's already almost fully implemented, just
needs some clean-up.



--
Ariya Hidayat, http://ariya.ofilabs.com
http://twitter.com/ariyahidayat

Teemu Ikonen

unread,
May 4, 2012, 12:07:40 AM5/4/12
to phan...@googlegroups.com
Thanks for update, I'll wait for the release!

/Teemu

Ariya Hidayat

unread,
May 4, 2012, 12:22:54 AM5/4/12
to phan...@googlegroups.com
Note that you are also free to improve the proposed pull request (it's
not completely done yet).


Regards,
Reply all
Reply to author
Forward
0 new messages