At Tue, 8 Jan 2002 06:53:20 +0900,
Neil Conway <nconway / klamath.dyndns.org> wrote:
> > > So I created a small script (I welcome criticism) to
> > > help me add some captions for a bunch of jpeg images:
> <snip>
> > > However, it would be nice to have the script pop up a small
> > > version of the image to look at while I write the caption.
> <snip>
> > Here's a quick-and-dirty solution, it isn't pretty but it should 
> > get you going (display is a part of ImageMagick):
> <snip>
> >   Thread.start do
> >       `display #{file}`
> >   end
> 
> This is probably better:
> 
> 	`display #{file} &`

trap(:CHLD) {wait(-1, Process::WNOHANG)}

Dir["*.jpg"].sort.each do |file|
  pid = fork {exec "display", file}
  begin
    puts "Enter caption for #{file}:"
    caption = gets
    if caption && caption!="\n" then
      File.open(File.basename(file,".jpg")+".txt","w") do |file|
        file.puts caption
      end
    end
  ensure
    Process.kill :TERM, pid
  end
end

# BTW, I want Process.spawn.

-- 
Nobu Nakada