0

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.

1
  • In ruby you can run native code surrounded with back tick characters ` ls /home. So then you need write parser that will parse result from previous code and create your ruby models. Commented Aug 16, 2013 at 3:30

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

This pretty much answers my question. Thanks Serj!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.