Project

General

Profile

Actions

Bug #3014

closed

select + read for STDIN unexpected result on Windows

Added by phasis68 (Heesob Park) about 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2dev (2010-03-26 trunk 27048) [i386-mswin32_90]
Backport:
[ruby-core:29018]

Description

=begin
I found that select and read combination for STDIN results "r u b y . e x e" on Windows.

Consider following code:
select([STDIN],nil,nil,10);puts STDIN.read(8)

I entered "test1234\n" for input.

On 1.8.6, it works fine.

C:>ruby -ve 'select([STDIN],nil,nil,10);puts STDIN.read(8)'
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]
test1234
test1234

On 1.9.x, it results "r u b y".

C:\work>ruby -ve 'select([STDIN],nil,nil,10);puts STDIN.read(8)'
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mingw32]
test1234
r u b y

C:\work>ruby -ve 'select([STDIN],nil,nil,10);puts STDIN.read(8)'
ruby 1.9.2dev (2010-03-26 trunk 27048) [i386-mswin32_90]
test1234
r u b y

C:\work>ruby -ve 'select([STDIN],nil,nil,10);p STDIN.read(8)'
ruby 1.9.2dev (2010-03-26 trunk 27048) [i386-mswin32_90]
test1234
"r\x00u\x00b\x00y\x00"

The result string is actually "r u b y . e x e" plus some garbage.
=end

Actions #1

Updated by yugui (Yuki Sonoda) about 14 years ago

  • Assignee set to usa (Usaku NAKAMURA)
  • Target version changed from 2.0.0 to 1.9.2

=begin

=end

Actions #2

Updated by phasis68 (Heesob Park) about 14 years ago

=begin

I found that STDIN.read(n) works when n >= 41.

I guess this bug is caused by PeekConsoleInput's bug or side effect.

Here is a guick and dirty patch.

--- win32.c 2010-03-26 19:04:28.502025030 +0900
+++ win32.c.new 2010-03-26 19:03:05.138310126 +0900
@@ -4851,6 +4851,10 @@
return _read(fd, buf, size);
}

  • if((_osfile(fd) & FDEV) && size <= 40) {

  •   return fread(buf, 1, size, stdin);
    
  • }

  • MTHREAD_ONLY(EnterCriticalSection(&(_pioinfo(fd)->lock)));

    if (!size || _osfile(fd) & FEOFLAG) {

=end

Actions #3

Updated by usa (Usaku NAKAMURA) almost 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r28035.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0