Bam
Bam

Reputation: 153

Times loop isn't looping

I'm creating a little script that will send 10 jobs to a printer. I'm trying to loop one of my methods using a times loop except when I run the program, it won't loop, it just send one job..

Example:

[<user>@<server> ruby]$ ruby clean_printer laser32
request id is laser32-1038115 (1 file(s))
[<user>@<server> ruby]$ 

Am I doing something wrong to where this won't loop..?

Source:

#!/usr/local/bin/ruby

class CleanPrinter

  attr_accessor :printer

  def initialize(printer)
    @printer = printer
  end

  def create_jobs
    exec("lp -d #{@printer} test.txt")
  end

  def loop
    10.times do
      create_jobs
    end
  end
end

test = CleanPrinter.new(ARGV[0])
test.loop

Yes it's a class, yes I will take it out of the class.

Upvotes: 2

Views: 66

Answers (1)

Yam Marcovic
Yam Marcovic

Reputation: 8141

Note that exec() actually replaces the current process image, thereby effectively exiting your program on the first iteration. You might want to switch to using system() instead.

Upvotes: 5

Related Questions