Forum: Ruby how to run a ruby program from another one

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.
Navya A. (Guest)
on 2006-02-28 09:21
(Received via mailing list)
Hi,

How can we run a a ruby program from another ruby program. I am working
on one program where in i have to run another ruby program from it.
I am stuck here.

Please help.

Thanks,
Navya
Bill K. (Guest)
on 2006-02-28 09:37
(Received via mailing list)
From: "Navya A." <removed_email_address@domain.invalid>
>
> How can we run a a ruby program from another ruby program. I am
> working on one program where in i have to run another ruby program
> from it.

Hi,

Usually

  result = `other_program`

or

  system("other_program")

or

  io = IO.popen("other_program", "r")  # or "w" if you want to write to
it
  io.gets  # ... read stdout from other_program
  ...


Regards,

Bill
Robert K. (Guest)
on 2006-02-28 10:56
(Received via mailing list)
Navya A. wrote:
> Hi,
>
> How can we run a a ruby program from another ruby program. I am
> working on one program where in i have to run another ruby program
> from it.
> I am stuck here.

The easiest is to use fork with a block:

09:51:31 [~]: ruby -e 'fork { puts "#{$$}: child" }; puts "#{$$}:
parent"'
1912: parent
2128: child

Kind regards

    robert
This topic is locked and can not be replied to.