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
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.
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/
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.
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 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
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.