# Exiting a ruby script

**URL:** <https://www.ruby-forum.com/t/exiting-a-ruby-script/88472>\
**Category:** Ruby\
**Created:** [March 11, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/exiting-a-ruby-script/88472 "2007-03-11T19:23:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@jasonb](https://www.ruby-forum.com/u/jasonb)\
**Post date:** [March 11, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/exiting-a-ruby-script/88472/1 "2007-03-11T19:23:48Z")

</div>

I’m in the process of playing around with a, application launcher  
script. It’s fairly far along, but I can’t seem to get the script to  
exit when the application is actually launched. Here’s the final bit of  
code:

@finalApps.each {|finalApp| if finalApp.id == runApp.to\_i  
updateRanking finalApp.name  
symbolMatch = finalApp.command.match(/  
%/)  
if symbolMatch  
system(symbolMatch.pre\_match)  
else  
system(finalApp.command)  
end  
end  
}

There’s some extra stripping of the command in there. The functional  
part is the internal if loop. After “system(symbolMatch.pre\_match)” or  
“system(finalApp.command)” the app launches properly, but in the console  
the ruby script stays open until the app is closed.

Is there a way to get the ruby script to terminate immediately after the  
app is successfully launched?

---

<div class="post-metadata">

**Author:** ![jasonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@jasonb](https://www.ruby-forum.com/u/jasonb)\
**Post date:** [March 11, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/exiting-a-ruby-script/88472/2 "2007-03-11T20:28:45Z")

</div>

Alle domenica 11 marzo 2007, Jason B. ha scritto:

> ```
> system(symbolMatch.pre_match)
> 
> ```
> 
> Is there a way to get the ruby script to terminate immediately after the  
> app is successfully launched?

If I understand your problem correctly, you should use exec instead of  
system,  
which replace the ruby interpreter with the command given as argumnt.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![jasonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@jasonb](https://www.ruby-forum.com/u/jasonb)\
**Post date:** [March 13, 2007, 5:01pm UTC](https://www.ruby-forum.com/t/exiting-a-ruby-script/88472/3 "2007-03-13T17:01:58Z")

</div>

Actually, the process still holds open while the “launched” app running.  
As soon as that last enter key is pressed to launch the app I need the  
ruby script to release the console.

> If I understand your problem correctly, you should use exec instead of  
> system
