Run other programs

lets say I have three programs

Main.rb
Sub1.rb
and
Sub2.rb

When I run Main.rb, I want it to access and run the other two ruby
programs. How do I do this?

On 1/26/07, Jonathan D. [email protected] wrote:

lets say I have three programs

Main.rb
Sub1.rb
and
Sub2.rb

When I run Main.rb, I want it to access and run the other two ruby
programs. How do I do this?

If you just want to run them one at a time and wait, you can do this;

trya.rb
puts “a”
sleep 3
system(“ruby tryb.rb”)
system(“ruby tryc.rb”)
sleep 3

tryb.rb
puts “b”
sleep 3

tryc.rb
puts “c”

From: Harry [mailto:[email protected]]:

From Jonathan D. [email protected]:

> lets say I have three programs

>

> Main.rb

> Sub1.rb

> and

> Sub2.rb

>

> When I run Main.rb, I want it to access and run the other two ruby

> programs. How do I do this?

>

If you just want to run them one at a time and wait, you can do this;

trya.rb

puts “a”

sleep 3

system(“ruby tryb.rb”)

system(“ruby tryc.rb”)

sleep 3

tryb.rb

puts “b”

sleep 3

tryc.rb

puts “c”

Just in case, he’s not familiar w ruby’s require yet.

C:\family\ruby>cat main.rb
puts FILE
require ‘sub1.rb’
require ‘sub2.rb’

C:\family\ruby>cat sub1.rb
puts FILE
C:\family\ruby>cat sub2.rb
puts FILE
C:\family\ruby>ruby main.rb
main.rb
./sub1.rb
./sub2.rb

C:\family\ruby>qri require
------------------------------------------------------ Multiple choice

 Kernel#require, Needle::Container#require,
 Needle::DefinitionContext#require

C:\family\ruby>qri kernel#require
--------------------------------------------------------- Kernel#requi
require(string) => true or false

 Ruby tries to load the library named _string_, returning +true+ i
 successful. If the filename does not resolve to an absolute path,
 it will be searched for in the directories listed in +$:+. If the
 file has the extension ``.rb'', it is loaded as a source file; if
 the extension is ``.so'', ``.o'', or ``.dll'', or whatever the
 default shared library extension is on the current platform, Ruby
 loads the shared library as a Ruby extension. Otherwise, Ruby tri
 adding ``.rb'', ``.so'', and so on to the name. The name of the
 loaded feature is added to the array in +$"+. A feature will not
 loaded if it's name already appears in +$"+. However, the file na
 is not converted to an absolute path, so that ``+require
 'a';require './a'+'' will load +a.rb+ twice.

hth
kind regards -botp

If you just want to run them one at a time and wait, you can do this;

trya.rb
puts “a”
sleep 3
system(“ruby tryb.rb”)
system(“ruby tryc.rb”)
sleep 3

tryb.rb
puts “b”
sleep 3

tryc.rb
puts “c”

thank you!
that was easy. so, according to
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_kernel.html#Kernel.system
when I use system(" ") it has the same effect as if I typed whatever is
in the quotes into the terminal, right?

I could also use load(“sub1.rb”) instead of system(“ruby sub1.rb”)
correct?

Is there a way I can propogate the variables in the loaded files
(‘sub1.rb’,sub2.rb’) to the loading file (‘main.rb’)?