# How to pass params to long running system call

**URL:** <https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545>\
**Category:** Rails\
**Created:** [June 16, 2006, 3:29am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545 "2006-06-16T03:29:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 3:29am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/1 "2006-06-16T03:29:47Z")

</div>

Hello,

Can someone tell me the best way to make a system call (from within my  
model) that runs for a while and requires params form my model,  
specifically attributes of my model.

So, I need the correct syntax and also general guidelines for launching  
the process.

Thanks so much.

Regards,  
Doug

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 3:46am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/2 "2006-06-16T03:46:23Z")

</div>

Could you be a little more specific? Like which OS, which system call,  
and what do you mean by ‘runs for a while’. The question is kind of  
vague.

Jason

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 4:07am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/3 "2006-06-16T04:07:30Z")

</div>

Jason R. wrote:

> Could you be a little more specific? Like which OS, which system call,  
> and what do you mean by ‘runs for a while’. The question is kind of  
> vague.
> 
> Jason

I’m running on linux and intend to call good ole system(). The call is  
to a perl script that could run anywhere from a 5 seconds to 60 seconds.

-Doug

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 4:38am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/4 "2006-06-16T04:38:56Z")

</div>

Douglass T. wrote:

> to a perl script that could run anywhere from a 5 seconds to 60 seconds.
> 
> -Doug

If you don’t care about the return value of this script, then this  
should work:

fork {  
exec(“perl\_script.pl”)  
}

Otherwise, throw a Ruby thread out and system() it.

script\_return = 0  
Thread.new {  
script\_return = system(“perl\_script.pl”);  
}.run

Though please correct me if I’m wrong, but that should get you going.

Jason

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 7:04am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/5 "2006-06-16T07:04:26Z")

</div>

that’ll work but do look in to DRb:

[http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

/r/r

On 6/16/06, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I’m running on linux and intend to call good ole system(). The call is  
> > }  
> > Jason
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rodney  
[http://www.pinupgeek.com](http://www.pinupgeek.com)  
[http://www.dutchrailers.org](http://www.dutchrailers.org)

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 8:29am UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/6 "2006-06-16T08:29:21Z")

</div>

On Jun 15, 2006, at 7:38 PM, Jason R. wrote:

> > 
> 
> fork {  
> exec(“perl\_script.pl”)  
> }

Don’t fork in your rails app. you will lose the database connection.

> Jason  
> While that may work, it won’t be very happy about it 😉 Especially if  
> you are trying to run a perl script that takes as long as you are  
> talking about. This is exactly the kind of thing I wrote backgroundrb  
> [1] for. You should check it out.\

Cheers-  
-Ezra

[1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 12:23pm UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/7 "2006-06-16T12:23:22Z")

</div>

Ezra Z. wrote:

> On Jun 15, 2006, at 7:38 PM, Jason R. wrote:
> 
> > > 
> > 
> > fork {  
> > exec(“perl\_script.pl”)  
> > }
> 
> Don’t fork in your rails app. you will lose the database connection.
> 
> > Jason  
> > While that may work, it won’t be very happy about it 😉 Especially if  
> > you are trying to run a perl script that takes as long as you are  
> > talking about. This is exactly the kind of thing I wrote backgroundrb  
> > [1] for. You should check it out.\
> 
> Cheers-  
> -Ezra
> 
> [1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)

Ezra,

I’m definitely going to check out backgroundrb. Wow, looks like a very  
good fit for my needs. Quick question, I notice you have methods in a  
controller class to handle launching jobs, progress bar, etc. What I  
envision is to launch a job and then simply have the job send an email  
to a particular address when it completes. Real simple. Are there any  
issues with backgroundrb if I want use this approach?

Thanks again for this,  
Doug

---

<div class="post-metadata">

**Author:** ![dugla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dugla](https://www.ruby-forum.com/u/dugla)\
**Post date:** [June 16, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/how-to-pass-params-to-long-running-system-call/63545/8 "2006-06-16T17:00:54Z")

</div>

On Jun 16, 2006, at 3:23 AM, Douglass T. wrote:

> > [1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)  
> > Thanks again for this,  
> > Doug

Hey Doug-

```
Yeah what you want to do would be no problem. You aren't forced to

```

use progress bars at all. In fact you can use the plugin like a fire  
and forget type of thing. I mean if you just kick it off from your  
rails app somewhere, then it can just do its thing and then send the  
email. You will want to run a simple cron script that does garbage  
collection of old worker instances every so often. The next major  
release will introduce a timing mechanism so old workers get garbage  
collected automatically. Or you will be able to set a time to live  
when you start the worker and it will commit suicide after the time  
runs out. There’s ifo abou ll of this stuff in the README as well as  
a script you can run from cron.

Cheers-  
-Ezra
