Starting a system command and letting it be?

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?

On 10/11/06, [email protected] [email protected] wrote:

You could just use ruby threads?

Farrel

On Fri, 10 Nov 2006, [email protected] wrote:

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

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:

and the rubyforge page: http://rubyforge.org/projects/backgroundrb/

OK, that was too obvious. :slight_smile:

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

OK, that was too obvious. :slight_smile:

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

Farrel L. wrote:

You could just use ruby threads?

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

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.

On Sat, 11 Nov 2006, [email protected] wrote:

OK, that was too obvious. :slight_smile:

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