From: Robert Klemme Date: 2009-08-26T18:13:11+09:00 Subject: Re: Asynchronous process to process pipe IO 2009/8/25 Pito Salas : > Robert Klemme wrote: > >> Then you'll want to use one of the popen family of functions.  Even with >> IO.popen you can pass arguments: >> >> IO.popen ["./iacommand.rb", "arg", "arg"] do |io| >>    ... >> end >> >> Note, if you also want to write to the process's stdin, you need to >> provide a file mode as second argument.  See docs. > > This is what I originally had. Pretty similar... > > open("|-", "r") do |worker| >    if worker > ... >    else >      exec("./iacommand.rb", "arg", "arg") >    end >  end > > How do you think that the idea you show above is different/better? I would prefer IO.popen as it is shorter - and it does not need cryptic (aka perlish) file names: IO.popen ["./iacommand.rb", "arg", "arg"], "rw" do |io| # no if here either io.puts "start" io.close_write io.each_line do |line| puts "GOT: #{line}" end end > This > gets pretty subtle... Thanks again for the great thread about Threads :) Sorry, I do not find it that subtle. IMHO it is pretty obvious that IO.popen is superfior for the job you want to get done. That is, of course, unless I am missing something... Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/