From: Joel VanderWerf Date: 2006-11-17T09:52:32+09:00 Subject: Re: Another IO.popen question ... ara.t.howard@noaa.gov wrote: > On Fri, 17 Nov 2006, Joel VanderWerf wrote: > >> Adam Groves wrote: >>> Hi Joel, >>> >>> thanks for the speedy reply! The problem is, I need to pass on a file >>> object (which has been uploaded from a web page form) to 'convert' >>> and not just a path. I should have made this clearer in my original >>> post. >>> >>> Any ideas? >>> >> >> Untested, but maybe something like this? >> >> file = File.open("mypdf.pdf") >> IO.popen("convert -resize 700x700 pdf:-[0] png:-") do |f| >> while (data=file.read(N)) >> f.write data >> end >> end > > careful, if you don't read the child will block when the pipe becomes > full i > think. you might need to add > > file = File.open("mypdf.pdf") > > png = > IO.popen("convert -resize 700x700 pdf:-[0] png:-") do |f| > while (data=file.read(N)) > f.write data > end > f.close_write > f.read > end > > not sure if that was obvious or not... sorry if it was. I was confused in several respects: I was thinking of a one-way pipe (but I forgot the "w"), in which case blocking wouldn't be a problem. But the one-way pipe would only be useful if the OP could put a filename in place of the "png:-". The one-way pipe has the advantage that you can read(N) instead of read(), and keep memory bounded. Maybe it's not an issues for the OP, though. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407