From: Hans Fugal Date: 2007-08-03T01:40:00+09:00 Subject: Piping two shell commands together I want to pipe two system commands together from within ruby. cmd1 and cmd2 are arrays, e.g. cmd1 = ['oggdec','-o','-',oldpath] cmd2 = ['lame','-',newpath] I think I can do the following, IO.popen('-','r') do |p1| exec cmd1 unless p1 IO.popen('-','w') do |p2| exec cmd2 unless p2 p2.write(p1.read) end end but I don't like the line "p2.write(p1.read)", because I think it will read into memory from p1 before turning around and writing it to p2. This may work for the above example, but it's not very pipelike and I worry that read might return early (I'm not sure what the semantics of that are in Ruby, but in C I'd have to account for that). Plus I don't like the popen '-'/exec combination. I'd love a more elgant, efficient, and/or safer idiom if anyone can think of one.