Waiting for process to finish

Well, all I could think of was to use polling:

def self.lpr_pdf(ps)
   system("lpr", "-P", "PDF", "-o", "number-up=2", "-o",
          "media=a4", "#{ps}")

   while true
     stat = `lpstat -p PDF -o`
     break if stat.match(/printer PDF is idle\./)
     puts "printing pdf . . ."
     sleep 1
   end
end

Is there not a better way?

···

On 30.03.2016 17:22, Joe Gain wrote:

I want to print a file from a ruby script using the cups pdf printer,
and I'm using Kernel#system like:

def self.lpr_pdf(ps)
   system("lpr", "-P", "PDF", "-o", "number-up=2", "-o",
     "media=a4", "#{ps}")
end

After the file has finished printing, I want to process it with pdfk
further. What's the best way to wait for the file to have finished
printing?