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
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.