# Mongrel crashes while running 'exec' through ruby

**URL:** <https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006>\
**Category:** Rails\
**Created:** [June 11, 2009, 8:54am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006 "2009-06-11T08:54:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tahir\_rauf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@tahir\_rauf](https://www.ruby-forum.com/u/tahir_rauf)\
**Post date:** [June 11, 2009, 8:54am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006/1 "2009-06-11T08:54:29Z")

</div>

Hi All,

I have a ruby on rails application and in the controller, I try to run a  
shell script using exec command

like this

* * *

## variable = ‘sh /home/abc.sh’ exec variable

But when the control comes at this line, the mongrel server immediately  
crashes, and when I check its status its says “missing pid file”.

The shell script contains nothing wrong, it works fine on the linux  
console, I have also commented everything in that shell script and put  
just a single variable declaration, but even then the serer crashes…

Any Ideas, or is there any other way to run a shell script using ruby on  
rails ??

Thanks in advance…

Tahir R.

---

<div class="post-metadata">

**Author:** ![tahir\_rauf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@tahir\_rauf](https://www.ruby-forum.com/u/tahir_rauf)\
**Post date:** [June 11, 2009, 9:14am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006/2 "2009-06-11T09:14:54Z")

</div>

On Jun 11, 7:54 am, Tahir R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi All,
> 
> I have a ruby on rails application and in the controller, I try to run a  
> shell script using exec command

You know that the whole point of the exec command is that it replaces  
the current process with what you tell it to run? You may be more  
interested in ``, system or things like IO.popen

Fred

---

<div class="post-metadata">

**Author:** ![tahir\_rauf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@tahir\_rauf](https://www.ruby-forum.com/u/tahir_rauf)\
**Post date:** [June 11, 2009, 9:31am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006/3 "2009-06-11T09:31:16Z")

</div>

Frederick C. wrote:

> On Jun 11, 7:54ï¿½am, Tahir R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi All,
> > 
> > I have a ruby on rails application and in the controller, I try to run a  
> > shell script using exec command
> 
> You know that the whole point of the exec command is that it replaces  
> the current process with what you tell it to run? You may be more  
> interested in ``, system or things like IO.popen
> 
> Fred

Thanks Fred, As far as i know system is for windows, and Currently my  
application is deployed on linux.

Can you tell me more about IO.popen ?

I just need to run a script and want the control back to the same  
process…

---

<div class="post-metadata">

**Author:** ![tahir\_rauf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@tahir\_rauf](https://www.ruby-forum.com/u/tahir_rauf)\
**Post date:** [June 11, 2009, 10:01am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006/4 "2009-06-11T10:01:49Z")

</div>

On Jun 11, 8:31 am, Tahir R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > interested in ``, system or things like IO.popen
> 
> > Fred
> 
> Thanks Fred, As far as i know system is for windows, and Currently my  
> application is deployed on linux.

That’s not true

> Can you tell me more about IO.popen ?

[http://www.ruby-doc.org/core/classes/IO.html#M002267](http://www.ruby-doc.org/core/classes/IO.html#M002267)

Fred

---

<div class="post-metadata">

**Author:** ![tahir\_rauf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@tahir\_rauf](https://www.ruby-forum.com/u/tahir_rauf)\
**Post date:** [June 11, 2009, 11:48am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/170006/5 "2009-06-11T11:48:56Z")

</div>

Got the solution, exec starts a new process so don’t use it…

just use the shell command in ruby like this

`sh /home/abc.sh`

in the controller…

It runs fine

Thanks Every body
