From: Robert Klemme Date: 2011-02-14T21:10:58+09:00 Subject: Re: System calls with ` in parameters On Mon, Feb 14, 2011 at 4:52 AM, Tanaka Akira wrote: > 2011/2/10 Robert Klemme : > >> Is there also a version which would return an IO or accept a block >> with IO parameter so we can feed something into the head of the >> pipeline and read from the tail? > > % ruby -ropen3 -e ' > Open3.pipeline_w(%w[head -6c], %w[cat -n]) {|w| >  w.write "ab\ncd\nef\n" > }' >     1  ab >     2  cd > > % ruby -ropen3 -e ' > Open3.pipeline_r(["echo", "foo`bar`baz"], ["head","-6c"]) {|r| >  p r.read > }' > "foo`ba" Very nice! I tried 13:09:25 Temp$ ./pl.rb < 1 000> < 2 001> < 3 002> < 4 003> < 5 004> 13:09:31 Temp$ cat pl.rb #!/bin/env ruby19 require 'open3' Open3.pipeline_rw(["cat", "-n"], ["sed", "-e", 's/^.*$/<&>/']) do |sin, sout, threads| th = Thread.new(sout) do |io| io.each_line do |l| puts l end end 5.times do |i| sin.printf "%03d\n", i end sin.close th.join end 13:09:58 Temp$ Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/