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

On Tue, Nov 22, 2011 at 10:39, Mario R. [email protected] 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.

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

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

On 22.11.2011 16:39, Mario R. 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

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

Vale,
Marvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOy8r/AAoJELh1XLHFkqhal3YH/jT/AZ4NOnA/Asp21hY3adWW
NIZ7FfFGmDltLOqqw/j4Yrzk5jPR3UsiiJGIq858UON+/z8xgL/+FMMnDJt1Jgao
rD5ViF4wHmUZcwS8dsXRFKz6B/xMiMIBcOsd/R/gFKoISA6T5oIEo+1B3atTsmjh
fU+Fj1rN07Puz9uMhYFXxOTU66LJvz0UvoRDei0ejBii6/J4pjGYI714/C0gup7r
ySNgvIxOvchnvL5iwqTS8q70z8HhsAsAqpnZSbtumgjTcoAePsfYXdXS1D3Dnk+k
hvmyJHTMzMhbz9VvqIaSDYMU2VhKZWsmUIYfrl5rtW1lVtLhPsHPyfWgIRKPKuw=
=o/NS
-----END PGP SIGNATURE-----

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

Dave A. wrote in post #1033126:

On Tue, Nov 22, 2011 at 10:39, Mario R. [email protected] 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.

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

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

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

OOps I see that is working on 1.8.7:

Marvin Gülker wrote in post #1033131:

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

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

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?

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 R.

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 R.