Starting a system command and letting it be?

D

darenbell

I'm writing a web service that accepts a call to initiate a few
self-contained scripts on a RHEL4 webserver. Being new to Ruby, I
can't seem to find any documentation on how I could kick off the
scripts without having the parent script wait on them to complete.
Obviously, I don't need arguments our output back from the scripts, so
all I'm concerned with is that they start and the parent can end
without killing them.

What's the best way to do this?
 
F

Farrel Lifson

I'm writing a web service that accepts a call to initiate a few
self-contained scripts on a RHEL4 webserver. Being new to Ruby, I
can't seem to find any documentation on how I could kick off the
scripts without having the parent script wait on them to complete.
Obviously, I don't need arguments our output back from the scripts, so
all I'm concerned with is that they start and the parent can end
without killing them.

What's the best way to do this?

You could just use ruby threads?

Farrel
 
A

ara.t.howard

I'm writing a web service that accepts a call to initiate a few
self-contained scripts on a RHEL4 webserver. Being new to Ruby, I
can't seem to find any documentation on how I could kick off the
scripts without having the parent script wait on them to complete.
Obviously, I don't need arguments our output back from the scripts, so
all I'm concerned with is that they start and the parent can end
without killing them.

What's the best way to do this?

by far the simplest is

system "in_the_background &"

-a
 
N

Nathan Witmer

What's the best way to do this?

Have a look at BackgrounDRb, it's a rails plugin designed specifically
for this type of thing: kicking off long-running tasks without making
rails wait for it to finish. You'll still probably use system() for
running your script, but if you use one of the popens (2, 3, or 4) you
can get stdout and feed that back to the rails app incrementally.

Here's an introductory article: http://www.infoq.com/articles/BackgrounDRb
and the rubyforge page: http://rubyforge.org/projects/backgroundrb/
 
D

darenbell

OK, that was too obvious. :)

Works fine in a local script, but my web service client is just sitting
there waiting. Guess that's the problem.
 
D

darenbell

OK, that was too obvious. :)

Works fine in a local script, but my web service client is just sitting
there waiting. Guess that's the problem.
 
A

ara.t.howard

OK, that was too obvious. :)

Works fine in a local script, but my web service client is just sitting
there waiting. Guess that's the problem.

perhaps, but probably caused by another issue. there's no reason why that
should not work from your web-server. if the client is hanging you've got
something else going on... show us the simplified code?

-a
 
D

David Vallner

--------------enigB3659C42E0039428074AD07E
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Farrel said:
=20
You could just use ruby threads?
=20

If the scripts do anything with standard input, they could hijack the
Ruby script's from the thread. Use popen, or the open('|some-script')
form instead of system?

David Vallner


--------------enigB3659C42E0039428074AD07E
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFVcrey6MhrS8astoRAlNUAJwKNQ8weyafMVtIJMwGUVKWO/Fp1ACcDUwO
MIBCr2OZxP6lv2jSmzN7FRo=
=Y5wj
-----END PGP SIGNATURE-----

--------------enigB3659C42E0039428074AD07E--
 
D

darenbell

Sorry for not responding sooner, but I was out of my office since my
last response. David's solution worked perfectly. Thanks for the help
everyone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top