# Restarting an application

**URL:** <https://www.ruby-forum.com/t/restarting-an-application/163206>\
**Category:** wxRuby\
**Created:** [March 18, 2009, 9:32am UTC](https://www.ruby-forum.com/t/restarting-an-application/163206 "2009-03-18T09:32:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![biospank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biospank](https://www.ruby-forum.com/u/biospank)\
**Post date:** [March 18, 2009, 9:32am UTC](https://www.ruby-forum.com/t/restarting-an-application/163206/1 "2009-03-18T09:32:11Z")

</div>

Hi folks,

i was wondering if is there any way to automatically restart wxruby  
application.

A sample code would be appreciated.

thank you all.

bio.

---

<div class="post-metadata">

**Author:** ![biospank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biospank](https://www.ruby-forum.com/u/biospank)\
**Post date:** [March 18, 2009, 11:32am UTC](https://www.ruby-forum.com/t/restarting-an-application/163206/2 "2009-03-18T11:32:34Z")

</div>

Fabio P. wrote:

> i was wondering if is there any way to automatically restart wxruby  
> application.

Can you explain a bit more what you mean? Under what circumstances would  
the application be ending? If it’s an exception, rescue it at the most  
appropriate level.

You can’t enter Wx::App’s main loop more than once in a script, but you  
can have no visible frames/dialogs. If you don’t want to end the  
application, hide() the frame, rather than close().

a

---

<div class="post-metadata">

**Author:** ![biospank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biospank](https://www.ruby-forum.com/u/biospank)\
**Post date:** [March 18, 2009, 12:58pm UTC](https://www.ruby-forum.com/t/restarting-an-application/163206/3 "2009-03-18T12:58:54Z")

</div>

Hi Alex,

Can you explain a bit more what you mean? Under what circumstances would  
the

> application be ending? If it’s an exception, rescue it at the most  
> appropriate level.

basically the idea i to upgrade the application via network and, after  
the  
upgrade process, restart to reload everything (xrc-layouts, models,  
configurations…).

---

<div class="post-metadata">

**Author:** ![biospank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biospank](https://www.ruby-forum.com/u/biospank)\
**Post date:** [March 18, 2009, 2:07pm UTC](https://www.ruby-forum.com/t/restarting-an-application/163206/4 "2009-03-18T14:07:03Z")

</div>

> This works for me on OS X:
> 
> Wx::App.run do  
> def self.on\_exit  
> exec(“ruby #$0”)  
> end  
> …  
> end

thank you, i’ll have a go with your solution

> If it’s an open app, I’d be interested to hear about/see examples of code  
> updating over net whenever you’re ready.

It’s just a vague idea, i don’t know yet how to implement it and tools  
to  
use, suggestions are wellcome.

cheers,

bio.

---

<div class="post-metadata">

**Author:** ![biospank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@biospank](https://www.ruby-forum.com/u/biospank)\
**Post date:** [March 18, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/restarting-an-application/163206/5 "2009-03-18T13:13:36Z")

</div>

Fabio P. wrote:

> basically the idea i to upgrade the application via network and,  
> after the upgrade process, restart to reload everything (xrc-layouts,  
> models, configurations…).

In that case I think the best thing would be to start a fresh ruby  
process, otherwise you will have all the old models etc already loaded.

This works for me on OS X:

Wx::App.run do  
def self.on\_exit  
exec(“ruby #$0”)  
end  
…  
end

This assumes the environment’s ruby is the right one to start the app.  
Note that you’ll want to have your editor handy to comment out the  
restart else you’ll end up in a permanent loop. In your case, you’ll  
want to wrap the exec in some sort of conditional which checks for  
restart after upgrade.

If it’s an open app, I’d be interested to hear about/see examples of  
code updating over net whenever you’re ready.

alex
