# Starting a system command and letting it be?

**URL:** <https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512>\
**Category:** Ruby\
**Created:** [November 10, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512 "2006-11-10T15:36:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/1 "2006-11-10T15:36:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/2 "2006-11-10T15:42:31Z")

</div>

On 10/11/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

You could just use ruby threads?

Farrel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 3:44pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/3 "2006-11-10T15:44:31Z")

</div>

On Fri, 10 Nov 2006, removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 4:00pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/4 "2006-11-10T16:00:33Z")

</div>

> 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:

> **[Introduction to BackgrounDRb](https://www.infoq.com/articles/BackgrounDRb/)**
>
> As the problem domain of your Rails applications expands, you may need to run computationally intensive or long running background tasks. How can you run these long background tasks without your web server timing out? And how do you display the...

and the rubyforge page: [http://rubyforge.org/projects/backgroundrb/](http://rubyforge.org/projects/backgroundrb/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 4:40pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/5 "2006-11-10T16:40:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/6 "2006-11-10T16:36:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 11, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/7 "2006-11-11T14:07:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2006, 2:56pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/8 "2006-11-13T14:56:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/starting-a-system-command-and-letting-it-be/75512/9 "2006-11-10T16:44:45Z")

</div>

On Sat, 11 Nov 2006, removed\_email\_address@domain.invalid wrote:

> 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
