Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronously reading stdin in Windows

I've been doing this to synchronously read the whole stdin data under Linux:

var buffer = fs.readFileSync('/dev/stdin');

This obviously won't work on Windows since there is no /dev/stdin file. What could I do to achieve the same?

like image 514
Gui Prá Avatar asked Dec 17 '22 06:12

Gui Prá


1 Answers

var size = fs.fstatSync(process.stdin.fd).size;
var buffer = size > 0 ? fs.readSync(process.stdin.fd, size)[0] : '';
like image 102
Sigmund Avatar answered Jan 05 '23 17:01

Sigmund