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

noreply at rubyforge.org noreply at rubyforge.org
Fri Jan 1 20:56:29 EST 2010

Bugs item #27640, was opened at 2009-12-31 05:08
You can respond by visiting: 

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:


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]



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

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


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)

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.

Park Heesob


You can respond by visiting: 

More information about the win32utils-devel mailing list