-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get file descriptor of process.{stdin,stdout,stderr} #2136
Comments
Is |
that should do, i think i had this same problem before, typescript typings didnt mention the fd's |
closing as answered |
Fixes: nodejs#28386 Refs: nodejs#31292 Refs: nodejs/help#2136
Fixes: #28386 Refs: #31292 Refs: nodejs/help#2136 PR-URL: #31395 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Fixes: #28386 Refs: #31292 Refs: nodejs/help#2136 PR-URL: #31395 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Fixes: #28386 Refs: #31292 Refs: nodejs/help#2136 PR-URL: #31395 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Fixes: #28386 Refs: #31292 Refs: nodejs/help#2136 PR-URL: #31395 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
anyone know how this can be accomplished given a file descriptor perhaps in a Node.js process? |
const fs = require("fs");
const getchar = function(){
const buffer = Buffer.alloc(1);
fs.readSync(process.stdin.fd/*0*/, buffer, 0, 1);
return buffer[0];
};
const readline = function(pmt){
process.stdout.write(pmt);
let c;
const buff = [];
while((c = getchar()) !== '\n'.charCodeAt(0)){
buff.push(c);
}
return Buffer.from(buff).toString("utf8");
}
const age = readline("your age: ");
console.log(`You are ${age} years old`);
const name = 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?
The text was updated successfully, but these errors were encountered: