You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
how to get file descriptor of process.{stdin,stdout,stderr} #2136
Is process.stdin.fd, process.stdout.fd, process.stderr.fd what you’re looking for? They do have fixed values, i.e. 0, 1 and 2, unless you are running code inside a Worker (in which case they are not associated with fds) or the streams have been overwritten with other objects.
Reacted by Alexander Mills, Jhony López and William Stein
process.stdin.fd seems to induce EAGAIN error when passed as an argument to fs.readSync.
When passing a literal 0 no error is thrown.
If this is a bug I'll file an issue.
Here is an example code
constfs=require("fs");constgetchar=function(){constbuffer=Buffer.alloc(1);fs.readSync(process.stdin.fd/*0*/,buffer,0,1);returnbuffer[0];};constreadline=function(pmt){process.stdout.write(pmt);letc;constbuff=[];while((c=getchar())!=='\n'.charCodeAt(0)){buff.push(c);}returnBuffer.from(buff).toString("utf8");}constage=readline("your age: ");console.log(`You are ${age} years old`);constname=readline("your name: ");console.log(`Your name is ${name}`);
On Node.js 8+, is there a way to get file descriptors for process.stdin, process.stdout, process.stderr in the node.js runtime?