Running C processes in Rails
开发者_开发知识库I make a call just like this:
value = ./simulated_annealing
Which is a C Object file, but Rails tells me it cannot find that file. I put it in the same dir that the rest of the models files (since it's called by one of those models), but I guess it should be in any other place.
I've tried that outside Ruby and it works great.
What do I have to do?
The thing is, when you say:
./simulated_annealing
you're explicitly saying: run file named simulated_annealing
which is found in the current directory. That's what the ./
means. If the file's located elsewhere you need to provide the path to it, or add that path to the environment variable $PATH. So, you should replace that line with:
/path/to/simulated_annealing
where /path/to
represents the actual path.
The best option is to use an absolute path for running the program. For ex., you can create a directory "bin" under your rails application top level directory. Place your program under "bin" directory. Then you can execute the program something like:
cmd = "#{RAILS_ROOT}/bin/cbin arg1 arg2"
value = `#{cmd}`
精彩评论