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
In v2.3.2+, first line is ignored, and second line is accepted:
foobarINPUT: bar
This problem occurs in only Windows + iojs v2.3.2+.
I don't use process.stdin.fd in non-Win because fs.readSync can't read it.
Therefore, process.stdin of v2.3.2+ might have problem. (not fs.readSync)
This is seems to be a regression that could have been introduced by 8cee8f5 (didn't do git bisect, just layman's bisecting). @nodejs/platform-windows ?
If 8cee8f5 made this problem, I think that windows label is not suitably, because I didn't use process.stdin in non-Win. And in case that doesn't use process.stdin (open('CONIN$') instead of it) in Windows is no problem.
Thank you, but... I tried your solution, and it did not read first line.
readyfoobarINPUT: bar
I tried your sample code on Windows 8.1 64bit with iojs v2.3.1, v2.3.2 and v3.1.0. Of course v2.3.1 works fine.
Also I tried 0 instead of process.stdin.fd. It works fine before accessing to process.stdin, but it doesn't read first line after accessing to process.stdin.
so is the issue that references to process.stdin initiate the readable stream, which does some buffering and that buffering prevents somebody from reading stdin like it was a file?
This issue came again, and it was fixed in v6.2.0.
Then, the versions of Node.js that have the problem:
VERSION >= 2.3.2 && VERSION < 4.2.4
VERSION >= 5.0.0 && VERSION < 5.1.0
VERSION >= 5.6.0 && VERSION < 6.2.0
Easy check:
varverNum=(function(ver){varnums=ver.replace(/^\D+/,'').split('.');varverNum=0;if((nums[0]=+nums[0])){verNum+=nums[0]*10000;}if((nums[1]=+nums[1])){verNum+=nums[1]*100;}if((nums[2]=+nums[2])){verNum+=nums[2];}returnverNum;})(process.version),hasProblem=verNum>=20302&&verNum<40204||verNum>=50000&&verNum<50100||verNum>=50600&&verNum<60200;if(hasProblem){console.log('TTY has problem.');}else{console.log('TTY has NO problem.');}
Activity
brendanashworth commentedon Aug 23, 2015
This is seems to be a regression that could have been introduced by 8cee8f5 (didn't do
git bisect, just layman's bisecting). @nodejs/platform-windows ?anseki commentedon Aug 23, 2015
If 8cee8f5 made this problem, I think that
windowslabel is not suitably, because I didn't useprocess.stdinin non-Win. And in case that doesn't useprocess.stdin(open('CONIN$')instead of it) in Windows is no problem.mscdex commentedon Aug 23, 2015
From what I can tell it has to do with
process.stdintaking so long to initialize when first accessed.For example, if you use:
Then the first line will get read as expected if you type it after
readyis displayed.mscdex commentedon Aug 23, 2015
You can also replace
process.stdin.fdin the original code with just0and it will get the first line too.I'm trying this all on Windows, so I haven't looked at it on *nix. Also, reverting 8cee8f5 does not affect this particular issue.
anseki commentedon Aug 24, 2015
Thank you, but... I tried your solution, and it did not read first line.
I tried your sample code on Windows 8.1 64bit with iojs v2.3.1, v2.3.2 and v3.1.0. Of course v2.3.1 works fine.
Also I tried
0instead ofprocess.stdin.fd. It works fine before accessing toprocess.stdin, but it doesn't read first line after accessing toprocess.stdin.For example, this code doesn't read first line:
Yes I know that
fdis meaningless now, then this works fine:But
process.stdinmight be used at a place I don't know. (e.g. other packages)That is, this code doesn't read first line:
I think that a point is that the programers don't know that
process.stdinmakes problem, and it should not so. (this is not designed behavior, right?)orangemocha commentedon Sep 9, 2015
@nodejs/streams : is it legal to use fs.readSync to read from process.stdin, which in this case is not a file?
calvinmetcalf commentedon Sep 9, 2015
so is the issue that references to process.stdin initiate the readable stream, which does some buffering and that buffering prevents somebody from reading stdin like it was a file?
anseki commentedon Sep 9, 2015
It seems that programmers use
read/readSyncwith STDIN to get the user's input easily instead ofprocess.stdin.on('data'). Also my module readlineSync triesreadSync.https://www.google.com/search?q=nodejs+read+from+stdin
This problem occurs when it reads from TTY. It seems no problem when it reads from the file or pipe. (e.g.
script < file,echo foo | scriptetc)anseki commentedon Oct 17, 2015
It seems that the Readline module also is affected by this problem.
For example:
In io.js v2.3.1-, no problem:
In io.js v2.3.2+, strange second line is shown:
Node.js v4.2.1 also returns same result:
anseki commentedon Oct 17, 2015
It seems that REPL also is affected by this problem.
I typed a first
1and pushed the Enter key.In io.js v2.3.1-, no problem:
In io.js v2.3.2+, strange second
1is shown:Node.js v4.2.1 also returns same result:
[-]fs.readSync of v2.3.2+ can't read first line from STDIN[/-][+]Input from STDIN is strange[/+][-]Input from STDIN is strange[/-][+]Input from TTY is strange[/+]anseki commentedon Oct 17, 2015
It seems that only the first line of both readline module and REPL is strange, like readSync.
#2504 (comment)
For example:
6 remaining items
silverwind commentedon Oct 22, 2015
Filed #3490 for the revert. I could use some assistence with a regression test for this.
src: Revert nix stdin _readableState.reading
src: Revert "nix stdin _readableState.reading"
src: Revert "nix stdin _readableState.reading"
src: Revert "nix stdin _readableState.reading"
src: Revert "nix stdin _readableState.reading"
src: Revert "nix stdin _readableState.reading"
anseki commentedon Jun 4, 2016
Related to #5384
This issue came again, and it was fixed in v6.2.0.
Then, the versions of Node.js that have the problem:
Easy check:
src: Revert "nix stdin _readableState.reading"