[Win32utils-devel] [ win32utils-Bugs-27640 ] Process.create :stdout fails in 1.9.1

noreply at rubyforge.org noreply at rubyforge.org
Sat Jan 2 21:00:55 EST 2010


Bugs item #27640, was opened at 2009-12-30 20:08
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=411&aid=27640&group_id=85

Category: win32-process
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Roger Pack (rogerdpack)
Assigned to: Nobody (None)
Summary: Process.create :stdout fails in 1.9.1

Initial Comment:
This demo:

http://wiki.github.com/rdp/ruby_tutorials_any_gem/win32-process

succeeds like a champ on ruby 1.8.6, fails to write to a file in 1.9.1 [both mingw, gem versions 0.6.2]

Thanks.
-r

----------------------------------------------------------------------

>Comment By: Roger Pack (rogerdpack)
Date: 2010-01-03 02:00

Message:
would you like to report it [appears you're a little more
familiar with the guts of the thing...]?
-r

----------------------------------------------------------------------

Comment By: Park Heesob  (phasis68)
Date: 2010-01-02 22:58

Message:
Yes, I think it must be reported as a bug.

Regards,
Park Heesob

----------------------------------------------------------------------

Comment By: Roger Pack (rogerdpack)
Date: 2010-01-02 22:31

Message:
does this need to be reported back to core then?
-r

----------------------------------------------------------------------

Comment By: Park Heesob  (phasis68)
Date: 2010-01-02 01:56

Message:
This is not a bug of win32-process but a bug of ruby 1.9.x.

Consider this code:
STDOUT.reopen(File.open('out.txt', 'w+')) 
system('ruby -v')

On ruby 1.8.6:
out.txt is
ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]

On ruby 1.9.1:
out.txt is

nothing

I noticed the root cause is FILE_FLAG_OVERLAPPED handling of ruby 1.9.x. I guess it is related with native thread supporting on windows. But the child process cannot handle the overlapped I/O on most cases.

In short, the inheritable file handle must not opened with the FILE_FLAG_OVERLAPPED flag.

To workaround is to disable FILE_FLAG_OVERLAPPED flag in win32-process side.
Insert following code after #686 of process.rb

if handle>50 # poor check for redirected handle
handle = ReOpenFile(handle,0x40000000,3,0)
end

Where ReOpenFile is defined as 
API.new('ReOpenFile', 'LLLL', 'L')
But this function is available on Windows 2003, Vista and Windows 7. Not working on XP or 2000.

Regards,
Park Heesob

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=411&aid=27640&group_id=85


More information about the win32utils-devel mailing list