From: Logan Capaldo Date: 2006-06-01T03:01:59+09:00 Subject: Re: Passing a string as stdin to a popen On May 31, 2006, at 11:30 AM, Pedro C�rte-Real wrote: > Say I have some content in a ruby string and I want to pass it as > stdin input to a command. I then want to read the output. > > I tried this: > > IO.popen("mycommand", mode='r+') do |io| > io.write mytext > result = io.read > end > > This resulted in a "Broken Pipe" exception. What's the correct way > to do this? > > Thanks, > > Pedro. > I'm not sure _exactly_ what the problem is, but I imagine that io.write mytext io.close_write # let the process know you've given it all the data result = io.read will fix things right up.