# How to run script/server in a thread?

**URL:** <https://www.ruby-forum.com/t/how-to-run-script-server-in-a-thread/138253>\
**Category:** Rails\
**Created:** [May 21, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/how-to-run-script-server-in-a-thread/138253 "2008-05-21T12:01:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [May 21, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/how-to-run-script-server-in-a-thread/138253/1 "2008-05-21T12:01:20Z")

</div>

I have an application in which a server part has been written using  
rails, and the client part using firewatir. I would like to fire both  
up with a single command. What mistake am I making below? I am  
running this from the app root folder, where I am able to fire up irb  
and successfully feed it exec(‘script/server’).

Warmly, Arun

#!/usr/bin/env ruby  
require ‘rubygems’  
#Include the FireWatir file.  
require ‘firewatir’  
#include the FireWatir Module.  
include FireWatir  
begin  
th=Thread.new{exec(‘script/server’)}  
sleep(3) #to give the server time to start. Is there a better way?  
ff=Firefox.new  
ff.goto(“[http://localhost:3000](http://localhost:3000)”)  
sleep (5)  
ensure  
ff.close  
th.terminate  
end

* * *

---

<div class="post-metadata">

**Author:** ![arunmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@arunmehta](https://www.ruby-forum.com/u/arunmehta)\
**Post date:** [May 21, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/how-to-run-script-server-in-a-thread/138253/2 "2008-05-21T12:13:08Z")

</div>

Your error is the use of exec() - exec() overwrites the whole process  
(all threads) with the new program. Use the system() instead…

izidor
