How to call an foreign program(compiled) from ruby?

H

Harry

Hi, I am trying to use some bin(like exe files under windows) file
under linux , these program is compiled from c++ source, can be
executed in command line . I am just wondering what is the simple way
to call these program from with the ruby program?

i think Rake might be the answer , I am not look things like FFI that
can handle c source , I just need to call an program ,pass it some
command line parameter, get some return data or some result file ,
that's enough

i notice some gem (generally speaking) can have some inbound bin file
in it's sub folder, I don't know how they glued together with ruby

can someone give some hint?

Thank you very much
 
W

Walton Hoops

I should probably also have mentioned, if you need the output,
%x is an easy way to save it:

irb(main):001:0> result = %x['uptime']
=> " 21:08:38 up 4 days, 8:47, 1 user, load average: 0.06, 0.01, 0.00\n"
irb(main):002:0> puts result
21:08:38 up 4 days, 8:47, 1 user, load average: 0.06, 0.01, 0.00
=> nil
irb(main):003:0>
-----Original Message-----
From: Walton Hoops [mailto:[email protected]]
Sent: Monday, October 12, 2009 9:05 PM
To: ruby-talk ML
Subject: Re: How to call an foreign program(compiled) from ruby?

The builtin system call is liekly what you need.
http://www.ruby-doc.org/core/classes/Kernel.html#M005971

-----Original Message-----
From: Harry [mailto:[email protected]]
Sent: Monday, October 12, 2009 7:45 PM
To: ruby-talk ML
Subject: How to call an foreign program(compiled) from ruby?

Hi, I am trying to use some bin(like exe files under windows) file
under linux , these program is compiled from c++ source, can be
executed in command line . I am just wondering what is the simple way
to call these program from with the ruby program?

i think Rake might be the answer , I am not look things like FFI that
can handle c source , I just need to call an program ,pass it some
command line parameter, get some return data or some result file ,
that's enough

i notice some gem (generally speaking) can have some inbound bin file
in it's sub folder, I don't know how they glued together with ruby

can someone give some hint?

Thank you very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,043
Members
48,769
Latest member
Clifft

Latest Threads

Top