Run an script without waiting to be done

Hi, I would like to know if it is possible to run an script without
waiting to be run. I mean, can I call another ruby script and not be
waiting for it to finish.
myScript1.rb
sleep 300

myScript2.rb
system("ruby myScript.rb")

so what I want is not be waiting until the end of myScript1.rb

···

--
Posted via http://www.ruby-forum.com/.

If you are running this on a Unix-type machine (including Linux and
Mac), you can "background" the second script by just putting an
ampersand (&) after the command, as in:

  system("ruby myScript.rb &")

the same way you would do to just run it in the background manually.

Now if you're on Windows, that's a whole 'nother story. You might
still be able to have the first script explicitly create a child
process that would replace itself with the second one. Google "fork
and exec" for how this is usually done in most languages; I haven't
looked into it in Ruby.

-Dave

···

On Tue, Nov 22, 2011 at 10:39, Mario Ruiz <tcblues@gmail.com> wrote:

Hi, I would like to know if it is possible to run an script without
waiting to be run. I mean, can I call another ruby script and not be
waiting for it to finish.

--
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

Use #spawn instead of #system. This works (with newer Ruby versions)
on Windows as well.

Vale,
Marvin

···

On 22.11.2011 16:39, Mario Ruiz wrote:

Hi, I would like to know if it is possible to run an script
without waiting to be run. I mean, can I call another ruby script
and not be waiting for it to finish. myScript1.rb sleep 300

myScript2.rb system("ruby myScript.rb")

so what I want is not be waiting until the end of myScript1.rb

This works on windows with just about any ruby:

t = Thread.new {
   system("ruby myScript.rb")
}

do_something_else

t.join # optionally, wait for process to finish

···

On 11/22/2011 07:39 AM, Mario Ruiz wrote:

Hi, I would like to know if it is possible to run an script without
waiting to be run. I mean, can I call another ruby script and not be
waiting for it to finish.
myScript1.rb
sleep 300

myScript2.rb
system("ruby myScript.rb")

so what I want is not be waiting until the end of myScript1.rb

Why not just run the second script (myScript.rb) directly? What's the
point of having a script that launches a separate one and then exits?

···

On 11/22/2011 10:39 AM, Mario Ruiz wrote:

Hi, I would like to know if it is possible to run an script without
waiting to be run. I mean, can I call another ruby script and not be
waiting for it to finish.
myScript1.rb
sleep 300

myScript2.rb
system("ruby myScript.rb")

so what I want is not be waiting until the end of myScript1.rb

--
Darryl L. Pierce <mcpierce@gmail.com>
http://mcpierce.multiply.com/
"What do you care what people think, Mr. Feynman?"

some of the machines run on Windows... and other on Linux

Dave Aronson wrote in post #1033126:

···

On Tue, Nov 22, 2011 at 10:39, Mario Ruiz <tcblues@gmail.com> wrote:

Hi, I would like to know if it is possible to run an script without
waiting to be run. I mean, can I call another ruby script and not be
waiting for it to finish.

--
Posted via http://www.ruby-forum.com/\.

Thanks We are working on Ruby 1.8.7 so no good news :frowning:

Marvin Gülker wrote in post #1033131:

···

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

--
Posted via http://www.ruby-forum.com/\.

On Windows, you can use `start ruby myScript.rb` - start is a command
that simply launches whatever was given to it in a separate command
line window. (It can also do some fancy stuff that's not relevant here
- you can learn more by typing `start /?` in cmd.)

-- Matma Rex

Thanks, I think this is what I was looking for

Bartosz Dziewoński wrote in post #1033164:

···

On Windows, you can use `start ruby myScript.rb` - start is a command
that simply launches whatever was given to it in a separate command
line window. (It can also do some fancy stuff that's not relevant here
- you can learn more by typing `start /?` in cmd.)

-- Matma Rex

--
Posted via http://www.ruby-forum.com/\.