Execute one Ruby script from inside another...

S

sketchitup

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
 
S

sketchitup

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
 
S

Sebastian Hungerecker

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top