# Mongrel crashes while running 'exec' through ruby

**URL:** <https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/196969>\
**Category:** Mongrel\
**Created:** [June 11, 2009, 8:56am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/196969 "2009-06-11T08:56:24Z")\
**Posts on this page:** 3\
**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:56am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/196969/1 "2009-06-11T08:56:24Z")

</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:26am UTC](https://www.ruby-forum.com/t/mongrel-crashes-while-running-exec-through-ruby/196969/2 "2009-06-11T09:26:01Z")

</div>

On Thu, Jun 11, 2009 at 08:56, Tahir R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

First of all, this is not a mongrel question at all, but a Ruby  
question, so  
please don’t follow up here. But anyway:

#exec replaces the current process and never returns and is probably not  
what you want to do in a controller. Have a look at

> **[Kernel#system - APIdock](https://apidock.com/ruby/Kernel/system)**
>
> Kernel#system - Ruby API documentation. View source code and usage examples.

and

[http://apidock.com/ruby/Kernel/`](http://apidock.com/ruby/Kernel/%60)

and

> **[IO.popen - APIdock](https://apidock.com/ruby/IO/popen/class)**
>
> IO.popen - Ruby API documentation. View source code and usage examples.

HTH,

/David

---

<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/196969/3 "2009-06-11T11:48:30Z")

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