-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Description
I'm currently writing a simple CLI with Node.js 6.1.0. Here's an example of how I'm trying to read from stdin:
'use strict';
const fs = require('fs');
const BUFFER_LENGTH = 8;
const buffer = Buffer.alloc(BUFFER_LENGTH);
fs.readSync(process.stdin.fd, buffer, 0, BUFFER_LENGTH);
console.log(buffer.toString());
When running this on OS X Yosemite (10.10.5), node exits with Error: EAGAIN: resource temporarily unavailable, read. Interestingly, it works if I replace process.stdin.fd with fs.openSync('/dev/stdin', 'rs').
Another point of interest is that I can use process.stdin.fd with Node.js 4.4.0 as long as I replace Buffer.alloc with a call to the deprecated Buffer constructor via new.
Finally, process.stdin.fd and fs.openSync('/dev/stdin', 'rs') don't return the same FD Number; on my system, the return values are 0 and 14 respectively.
Am | missing something obvious or is there a potentially bug with process.stdin.fd on OS X/Node.js 6?
Thanks for your time,
James