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

**URL:** <https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194>\
**Category:** Ruby\
**Created:** [October 13, 2009, 3:45am UTC](https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194 "2009-10-13T03:45:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [October 13, 2009, 3:45am UTC](https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194/1 "2009-10-13T03:45:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [October 13, 2009, 5:05am UTC](https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194/2 "2009-10-13T05:05:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [October 13, 2009, 5:12am UTC](https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194/3 "2009-10-13T05:12:25Z")

</div>

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\>

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [October 13, 2009, 8:55am UTC](https://www.ruby-forum.com/t/how-to-call-an-foreign-program-compiled-from-ruby/177194/4 "2009-10-13T08:55:26Z")

</div>

Thankd Walton ,

that was exactly what I need ! thank you very much!
