Daniel Berger
2008-Feb-27 03:28 UTC
[Win32utils-devel] Making redirecting output with win32-process a bit easier
Hi all, Inspired by Sander Pool''s help request, I came up with this change to win32-process which makes redirecting stdin/stdout/stderr less of a hassle: C:\Documents and Settings\djberge\workspace\win32-process\lib\win32>diff -u process.orig process.rb --- process.orig Tue Feb 26 22:23:56 2008 +++ process.rb Tue Feb 26 22:23:20 2008 @@ -270,6 +270,10 @@ # library. Note that the ''stdin'', ''stdout'' and ''stderr'' options can be # either Ruby IO objects or file descriptors (i.e. a fileno). However, # StringIO objects are not currently supported. + # + # If ''stdin'', ''stdout'' or ''stderr'' are specified, then the +inherit+ value + # is automatically set to true and the Process::STARTF_USESTDHANDLES flag is + # automatically OR''d to the +startf_flags+ value. # # The ProcessInfo struct contains the following members: # @@ -381,8 +385,10 @@ if handle == INVALID_HANDLE_VALUE raise Error, get_last_error end - + si_hash[io] = handle + si_hash[''startf_flags''] |= STARTF_USESTDHANDLES + hash[''inherit''] = true end } This would eliminate the need to remember that the startf_flags and inherit value must be set properly in order for redirection to work with Process.create. Also, it means less typing for the user. :) What do you think? Regards, Dan