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}`);
Activity
addaleax commentedon Aug 21, 2019
Is
process.stdin.fd,process.stdout.fd,process.stderr.fdwhat 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.ORESoftware commentedon Aug 22, 2019
that should do, i think i had this same problem before, typescript typings didnt mention the fd's
gireeshpunathil commentedon Dec 27, 2019
closing as answered
doc: document process.std*.fd
doc: document process.std*.fd
doc: document process.std*.fd
doc: document process.std*.fd
ORESoftware commentedon Mar 30, 2020
anyone know how this can be accomplished given a file descriptor perhaps in a Node.js process?
https://unix.stackexchange.com/questions/576954/discover-what-file-stdout-is-being-written-to
martian17 commentedon Apr 3, 2023
process.stdin.fdseems to induceEAGAINerror when passed as an argument tofs.readSync.When passing a literal
0no error is thrown.If this is a bug I'll file an issue.
Here is an example code