2

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}")
farnoy
  • 7,356
  • 2
  • 20
  • 30
sunnyrjuneja
  • 6,033
  • 2
  • 32
  • 51

2 Answers2

4

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
Jiemurat
  • 1,619
  • 20
  • 20
2

Use global constant ARGV (although there's not much to learn) to receive an array of strings with the parameters.
So for your case:

require 'daemons'

files = []
ARGV.each do |arg|
  files << File.expand_path(arg)
end

This should give you absolute paths to every argument, so that you can open them from anywhere.

farnoy
  • 7,356
  • 2
  • 20
  • 30