# Call a program

**URL:** <https://www.ruby-forum.com/t/call-a-program/112366>\
**Category:** Ruby\
**Created:** [August 17, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/call-a-program/112366 "2007-08-17T23:45:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 17, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/call-a-program/112366/1 "2007-08-17T23:45:49Z")

</div>

Hi all,

Can anyone help me with the following issue: How can I call a program  
(such as less, g++ etc.) from ruby script and save the output to a  
variable inside the ruby script?

Thanks,  
Greg

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 17, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/call-a-program/112366/2 "2007-08-17T23:55:49Z")

</div>

On 17.08.2007 23:42, greg wrote:

> Can anyone help me with the following issue: How can I call a program  
> (such as less, g++ etc.) from ruby script and save the output to a  
> variable inside the ruby script?

The easiest forms are these

x=`ls -l`  
x=%x{ls -l}

For more complex interactions please look at various versions of popen.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 17, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/call-a-program/112366/3 "2007-08-17T23:58:50Z")

</div>

On Aug 17, 2007, at 17:44 , greg wrote:

> Hi all,
> 
> Can anyone help me with the following issue: How can I call a program  
> (such as less, g++ etc.) from ruby script and save the output to a  
> variable inside the ruby script?

ls = `ls -la`

HTH,

~Wayne

s///g  
Wayne E. Seguin  
Sr. Systems Architect & Systems Administrator
