From: Daniel N Date: 2006-08-04T13:58:56+09:00 Subject: Re: How to tell when IO::popen is finished? ------=_Part_26508_8724786.1154667531884 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/4/06, Daniel N wrote: > > On 8/4/06, ara.t.howard@noaa.gov wrote: > > > > > 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? > > > > > > > ?? it's set to the first command line parameter > > > > >> harp:~ > cat a.rb > > >> require 'rubygems' > > >> require 'gnuplot' > > >> > > >> PNG = ARGV.shift || 'test.png' > > > > it can be anything you like. > > > > > > you have one of two problems: > > > > - /test2.png is being interpreted as some sort of switch. definitely > > try > > without the leading slash - that's a bizarre filename anyhow... > > > > - the gnuplot exe is not being found in your PATH. search the > archives > > - > > i've solved this one before. > > > > regards. > > > > -a > > -- > > happiness is not something ready-made. it comes from your own actions. > > - h.h. the 14th dali lama > > > Sorry Ara, I must be really thick at this because I don't understand, > except > the PNG part... whoops ;) > > The chart is created, so the exe is found and executed. > > /test2.png, bizarre as it is, is created correctly at c:\test2.png and I > can > open it no problem once its written. > > The issue is that when I call make_chart and then immediately try to do > something with c:\test2.png it doesn't exist yet. I need to wait for it > to > be written. > > eg > make_chart > chart_file = File.open( 'c:/test2.png' ) #< raises and exception because > the > file does not yet exist > > I would have thought that since Gnuplot.open has IO::popen as it's last > statement it would return some kind of IO object, but it returns a > Gnuplot::Plot object. > > Sorry if I'm going around circles. I appreciate your help with this. > > Daniel I'm really trying to grok how this works. In the docs for IO it says that the block will return the results of the block, not an IO object. Sorry I didn't pick this up earilier. The other thing that I found in there, I think, was that when the pipe is opened, the ruby side of the pipe evaluates the block, sends its results and then closes. I guess this is why I'm having trouble. Ruby executes the block and closes then moves onto the next statment, but gnuplot, on the other end of the pipe is still doing it's thing drawing the chart. If it doesn't finish before the ruby moves on I get the exception. Am I understanding this correctly? If I am, is there any way to get at the process that gnuplot is running so I can tell when it's finished? Cheers Daniel ------=_Part_26508_8724786.1154667531884--