From: Daniel N Date: 2006-08-03T23:39:36+09:00 Subject: Re: How to tell when IO::popen is finished? ------=_Part_9841_7843118.1154615967509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/4/06, ara.t.howard@noaa.gov wrote: > > On Thu, 3 Aug 2006, Daniel N wrote: > > > Hi, > > > > I've just installed and had some success with the gnuplot library. > > > > I'm saving the output to a png file (plot.terminal "png") and this all > works > > well, but when I try to use the file it isn't finished writing it yet > and I > > get an exception. > > > > I've used > > > > Gnuplot.open( ) do |gp| > > .... > > end > > > > while(!File.exists?("/test2.png") || File.zero?("/test2.png") ) > > sleep 0.1 > > end > > > > In an attempt to wait until the file is written before I try to do > anything > > with it, but this seems a bit too hackish. > > > > Can I capture the Gnuplot.open into a variable and check it? The last > > statement in the Gnuplot.open is a call to > > IO::popen( cmd, "w") { |io| yield io } > > > > but if I test the class of what is returned it is > > Gnuplot::Plot > > > > not anything to do with IO > > > > Is there a way that I can test the IO::popen to tell when it's finished? > > > > can you show the code? that pipe will be automatically closed once the > yield > has returned. > > -a > -- > we can never obtain peace in the outer world until we make peace with > ourselves. > - h.h. the 14th dali lama > > I'm using Gnuplot the open method is def Gnuplot.open( persist=true ) cmd = Gnuplot.gnuplot( persist ) or raise 'gnuplot not found' IO::popen( cmd, "w") { |io| yield io } end Then my method def make_chart( ) Gnuplot.open() do |gp| Gnuplot::Plot.new(gp) do |plot| plot.terminal "png" plot.output "/test2.png" plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" x = (0..200).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "lines" ds.notitle ds.linewidth = 6 end end end end make_chart while(!File.exists?("/test2.png") || File.zero?("/test2.png") ) sleep 0.1 end ------=_Part_9841_7843118.1154615967509--