From: Daniel N Date: 2006-08-04T08:19:48+09:00 Subject: Re: How to tell when IO::popen is finished? ------=_Part_22064_8463276.1154647177696 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: > > >> I'm using Gnuplot the open method is > > > > this works fine on my box: > > harp:~ > cat a.rb > require 'rubygems' > require 'gnuplot' > > PNG = ARGV.shift || 'test.png' > > def Gnuplot.open( persist=true ) > cmd = Gnuplot.gnuplot( persist ) or raise 'gnuplot not found' > IO::popen( cmd, "w") { |io| yield io } > end > > > def make_chart( ) > Gnuplot.open() do |gp| > Gnuplot::Plot.new(gp) do |plot| > plot.terminal "png" > plot.output 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 > > p File.stat(PNG) > > # works if you have image magick installed > system "display #{ PNG }" > > > harp:~ > ruby a.rb > # gid=447, rdev=0x51e1, size=3583, blksize=4096, blocks=8, atime=Thu Aug 03 > 08:53:07 MDT 2006, mtime=Thu Aug 03 08:53:50 MDT 2006, ctime=Thu Aug 03 > 08:53:50 MDT 2006> > > > i think your issue was '/test2.png' - unless you're root i doubt you can > open > that file. > > regards. > > -a > -- > we can never obtain peace in the outer world until we make peace with > ourselves. > - h.h. the 14th dali lama > > I'm on windows :) I don't need root. Ohhh gives me goosebumps ;) The problem isn't that the file isn't created. It's just that I don't know when it's finished being written. I want to incorporate this into an app but I don't want to go trying to grab the image if it doenst exist yet. I'm not quite sure how your using PNG in your code above. Is this a constant of gnuplot? ------=_Part_22064_8463276.1154647177696--