Search code examples
rubydaemons

Passing arguments to a ruby script


I run a file like this:

ruby hello.rb world.csv data.csv

How would the start file look? I have this.

require 'daemons'

pwd  = File.dirname(File.expand_path(__FILE__))

wFile = "#{pwd}/world.csv"
dFile = "#{pwd}/data.csv" 

Daemons.run("hello.rb #{wFile} #{dFile}")

Solution

  • You must create a file hello_daemon.rb like this:

    require 'daemons'
    
    Daemons.run("hello.rb")
    

    And run it (you can use one of start, restart or run):

    ruby hello_daemon.rb start -- world.csv data.csv
    

    And daemons will run your hello.rb as

    ruby hello.rb world.csv data.csv