[Win32utils-devel] streams in fork

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Wed Dec 1 14:39:33 EST 2004

On Wed, 24 Nov 2004 10:52:24 -0600, win32utils-devel at rubyforge.org
<win32utils-devel at rubyforge.org> wrote:
> > -----Original Message-----
> > From: win32utils-devel-bounces at rubyforge.org
> > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
> > win32utils-devel at rubyforge.org
> > Sent: Tuesday, November 23, 2004 9:01 PM
> > To: win32utils-devel at rubyforge.org
> > Subject: [Win32utils-devel] streams in fork
> >
> >
> > hi all,
> >
> > is there a way to use fork with redirected streams? i mean in
> > a similar way that ruby's standard open3 does it.
> >
> > i'd like to be able to read the stdout/stdin/stderr streams
> > from the forked ruby process in the parent process.
> >
> > cheers,
> > aslak
> Do you mean so that you could create pipes using IO.popen for example?
> Not at the moment, but it's something I would like to have implemented
> at some point.
> If that's not what you meant, can you provide an example of what you
> wish to accomplish?

Here is what I need to accomplish:

I am writing a Ruby app (DamageControl -
http://damagecontrol.codehaus.org/) that needs to execute on both
native windows Ruby (i.e. no cygwin) and Linux/Unix Ruby - using the
same ruby source code.

DamageControl regulary spawns child processes and reads their stdout
and stderr streams. I need to know the pid for these processes so they
can be killed in the event of a app shutdown or if the process takes
longer to execute than some timeout value that I specify. I also need
to be able to wait for the process to return. To summarise I need to:

o spawn a child process
o get its stdin, stdout and stderr streams
o get its pid
o wait for it to complete
o kill it if i want
o set environment variables only available to the child

I tried with your fork implementation, but discovered it wouldn't give
me the streams.
Then I tried with the open3 implementation, which doesn't give me the pid.

I have submitted a patch for open3 (http://tinyurl.com/5b9ja) that
turns it into an open4, which gives the pid.

-So all my requirements seem to be satisfied except for the last one (env vars).

If you think there are other ways to accomplish what I need it would
be great to know. I also hope you have some feedback on my 2 patches.
(It turns out I probably won't use fork unless support is added to


> Dan
> _______________________________________________
> win32utils-devel mailing list
> win32utils-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/win32utils-devel

More information about the win32utils-devel mailing list