2013-08-16 80 views
0

我遇到了一些需要帮助的情况。它涉及在Ubuntu服务器上运行的ruby,rails和本地c应用程序。在Ubuntu服务器上通过ruby脚本启动C可执行文件

我能够在服务器上编译c应用程序,现在需要知道如何通过ruby脚本启动它们。

我的最终目标是从Rails应用程序中获取数据列表,将它们保存到服务器上的特定.dat文件中,将此文件用作我的可执行文件的输入(以及标记),并加载生成的文件通过一个红宝石脚本回到我的Rails应用程序中进行显示。

我目前看这些开始:

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?

如果有人做了这样的事或有如何的想法做到这一点,请指教。

+0

在Ruby中,你可以运行本地代码。那么你需要编写解析器来解析以前代码的结果并创建你的ruby模型。 – hawk

回答

3

你可以不喜欢与反勾字```LS/home``包围该

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 

或者

#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 
+0

这几乎可以解答我的问题。谢谢Serj! – rjd

相关问题