From: Robert Klemme Date: 2010-03-02T06:35:11+09:00 Subject: Re: IO.popen with Threads On 01.03.2010 21:51, Eikichi On wrote: > Hi everyone, > > I am trying to use IO.popen in order to put and get messages from a > process to its sub-process (according to > http://ruby-doc.org/core/classes/IO.html#M002242). > > I am not experimented and I have two questions about: > > 1/ Do threads are a good choice, for read and write at the same time > (with IO.popen)? Yes. > Have you got a simple exemple? Please see answer to second question. > 2/ I think IO.popen is useful for asynchrone communication. But when I > just need to send a message from a process to its sub-process, and wait > its answer, how should we do it? (any example is very appreciated) reply = IO.popen ["cat", "-n"], "r+" do |io| rdr = Thread.new { io.read } # alternative: io.readlines io.puts "message", "you", "want to send" io.close_write rdr.value # joins and fetches the result end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/