# Re: Calling Shell Scripts from Ruby?

**URL:** <https://www.ruby-forum.com/t/re-calling-shell-scripts-from-ruby/59396>\
**Category:** Ruby\
**Created:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/re-calling-shell-scripts-from-ruby/59396 "2006-05-03T18:59:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gennady\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@Gennady\_B](https://www.ruby-forum.com/u/Gennady_B)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/re-calling-shell-scripts-from-ruby/59396/1 "2006-05-03T18:59:52Z")

</div>

> 1)Is it possible to call “Shell Scripts” from ruby? Say if i  
> have a shell sciprt named “test.sh”, how can i call this from  
> ruby? Also if i can call like that,is it possible to get the  
> output of that script passed back to ruby?

Shell scripts fall into “any Unix command” category, so keep on reading.

> 2)How can i call any “Unix command” residing from a ruby program??

1. Backquotes

result = `test.sh`

1. exec(), fork/exec

# exec ‘test.sh’

Process.wait fork {  
exec ‘test.sh’  
}

1. popen(), popen3(), etc.

IO.popen(‘test.sh’) { |\_io|  
\_io.readlines()  
}

1. Good old system()

system(‘test.sh’)

Read about all those facilities in the documentation to get the most out  
of it.

Gennady.
