matt neuburg wrote:
> Hans Fugal <fugalh / zianet.com> wrote:
> 
>> matt neuburg wrote:
>>> Hans Fugal <fugalh / zianet.com> wrote:
>>>
>>>> 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 don't know about the arrays, but you can say IO.popen ("oggdec |
>>> lame").... m.
>>>
>> Yeah, that won't work here (unless there's a reliable way to 
>> shell-quote/escape oldpath and newpath).
> 
> I'm a little confused about oldPath. Once you have told IO.popen to
> generate an IO instance (let's call it ios), whatever you write to ios
> passes thru the process. So you don't actually need to tell IO.popen
> about oldpath; you just write the data.
> 
> As for quoting, I just put quotes around it.
> 
> So, for example, a way to do LAME encoding with Ruby is like this:
> 
> oldpath = "/Users/mattneub/some sound file.aif"
> newpath = "/Users/mattneub/some sound file.mp3"
> s = "lame --preset standard - '#{newpath}'"
> IO.popen(s, "r+") do |ios|
>   ios.write(File.read(oldpath))
> end
> 
> So maybe you could say:
> 
> s = "oggdec -R -o - - | lame ... - '#{newpath}'"
> 
> I've suggested -R because the oggdec man page warns not to write WAV to
> stdout. But then I've omitted some lame params (...) because you'll
> probably need to tell lame what kind of raw data it's receiving. I
> haven't tried this, though.

What happens when you try to encode to newpath = "Beethoven's 5th" or 
something with an apostrophe?

I did come up with a working solution, which you can read about here: 
http://hans.fugal.net/blog/articles/2007/08/02/pipelining-processes-in-ruby

Cheers