From: Robert Klemme Date: 2009-12-30T06:15:04+09:00 Subject: Re: IO.popen('-') === fork ? On 12/29/2009 09:54 PM, Nilez Parker wrote: >> fork does nothing to redirect stdin, stdout and stderr while popen in >> the form you used will send the sub process's stdout to a pipe. So >> the answer is: no, they are not equivalent. Rather popen uses some >> form of fork under the hood. > > Thanks Robert. I think I meant to ask whether Process.popen uses the > same OS fork call as Process.fork does. > > I found what I need for now though, so I'm posting it partly just for > people who find this via google later on. I wanted some pipes between > parent and children, and this is what I came up with: > > children = [] > 3.times do > from_child, to_parent = IO.pipe > from_parent, to_child = IO.pipe > fork do > # don't need to read from or write to child > to_child.close > from_child.close > to_parent.write "READY" > loop { ... } > end > children << to_child > # don't need to read from or write to parent > to_parent.close > from_parent.close > end > # Now the parent has a read/write IO pair for each child stored in > `children'; each child has a read/write IO pair for the parent. I don't see why you go through this instead using one of the #popen family of methods (there is also #popen3). > Thanks Robert for the quick answer, and I'm still curious whether > Process.popen uses the same OS fork call as Process.fork does. Underneath it is eventually the same, yes. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/