Forum: Ruby Execute one Ruby script from inside another...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D69a157357986644e32850b162774a69?d=identicon&s=25 sketchitup@gmail.com (Guest)
on 2007-07-27 21:42
(Received via mailing list)
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
D69a157357986644e32850b162774a69?d=identicon&s=25 sketchitup@gmail.com (Guest)
on 2007-07-27 21:46
(Received via mailing list)
On Jul 27, 12:38 pm, "sketchi...@gmail.com" <sketchi...@gmail.com>
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

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

Thanks,

The SketchUp Article
7a561ec0875fcbbe3066ea8fe288ec77?d=identicon&s=25 Sebastian Hungerecker (Guest)
on 2007-07-27 21:58
(Received via mailing list)
sketchitup@gmail.com 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
This topic is locked and can not be replied to.