# Execute one Ruby script from inside another

**URL:** <https://www.ruby-forum.com/t/execute-one-ruby-script-from-inside-another/110591>\
**Category:** Ruby\
**Created:** [July 27, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/execute-one-ruby-script-from-inside-another/110591 "2007-07-27T21:42:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/execute-one-ruby-script-from-inside-another/110591/1 "2007-07-27T21:42:44Z")

</div>

Is it possible to execute one Ruby script from inside another Ruby  
script? What is the syntax for this? Can arguments be passed to the  
second script from inside the first?

What about other external programs? Can Ruby execute those?

Thanks for the help.

The SketchUp Artist

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/execute-one-ruby-script-from-inside-another/110591/2 "2007-07-27T21:46:48Z")

</div>

On Jul 27, 12:38 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is it possible to execute one Ruby script from inside another Ruby  
> script? What is the syntax for this? Can arguments be passed to the  
> second script from inside the first?
> 
> What about other external programs? Can Ruby execute those?
> 
> Thanks for the help.
> 
> The SketchUp Artist

I apologize. I just found the answer to the first part of my question  
in this article:

[http://ruby.about.com/od/learnruby/ss/require\_load\_2.htm](http://ruby.about.com/od/learnruby/ss/require_load_2.htm)

I’d still like to know if Ruby can execute external programs.

Thanks,

The SketchUp Article

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/execute-one-ruby-script-from-inside-another/110591/3 "2007-07-27T21:58:48Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I’d still like to know if Ruby can execute external programs.

It sure can:

system(“app”)  
will execute app with the parameters arg1 and arg2. It will return true  
if the  
programm exited successfully, false otherwise. app’s output will go to  
stdout  
(unless you redirect it).

`app` or %x{app}  
will execute app and return its output as a string.

IO::popen(“app”,mode)  
will execute app and immediately return an IO object (i.e. unlike the  
previous  
options it won’t wait for app to finish). You will be able to interact  
with  
app using said IO object.

Open3::popen3(“app”)  
works the same way as popen, except it gives you _three_ IO objects. One  
to  
write to app’s input stream, one to read from its output stream and one  
to  
read from its error stream.

That’s it.

HTH,  
Sebastian
