Reputation: 1806
I have a situation I need some assistance with. It involves ruby, rails, and a native c applications running on an Ubuntu server.
I am able to compile the c applications on the server and now need to know how to launch them via ruby script.
My end goal is to take lists of data from a rails app, save them to a specific .dat file on the server, use this file as the input to my executables (along with flags), and load the resulting files back through a ruby script into my rails app for display.
I'm currently looking at these to start:
Confirm existance of executable (script, bat, cmd, exe) via a ruby file
Launch a script on a separate server from a Rails app
Confirm existance of executable (script, bat, cmd, exe) via a ruby file
Ruby require_relative executing script?
If anyone has done anything like this or has ideas of how to do it please advise.
Upvotes: 0
Views: 106
Reputation: 86
You can do like this
original_file_path = 'path/to/original_file.dat'
modified_file_path = 'path/to/modified_file.dat'
File.write(file_path, 'data')
#this will return an output from c program
#use this if you need to parse output from c program
result = `some_c_executable --some_flag #{file_path}`
#parsing result...
data = File.read(modified_file_path)
#work with data
Or
#if you don't need output from c program, use "system"
#it returns you true or false according to success
result = system "some_c_executable --some_flag #{file_path}"
if result
data = File.read(modified_file_path)
#work with data
else
...
end
Upvotes: 3