[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

loop a program on exit?

Michael Linfield

9/16/2007 5:51:00 AM

i want to have a program restart when its closed via the X button on the
window / terminal

any ideas?
--
Posted via http://www.ruby-....

9 Answers

John Joyce

9/16/2007 2:40:00 PM

0


On Sep 16, 2007, at 12:51 AM, Michael Linfield wrote:

> i want to have a program restart when its closed via the X button
> on the
> window / terminal
>
> any ideas?
> --
> Posted via http://www.ruby-....
>
You're going into very platform specific territory there. Potentially
malware like behavior.
Normally, the paradigm a user expects is that a GUI widget functions
the same as in other applications. If all you want is to have an
application not quit via that GUI widget, disable that widget, and
visually gray it out.
If you want a restart button, make one.
Don't break expected behaviors like that.
If you want a daemon process, you probably don't want it running in a
GUI.

Lloyd Linklater

9/16/2007 6:05:00 PM

0

Michael Linfield wrote:
> i want to have a program restart when its closed via the X button on the
> window / terminal
>
> any ideas?

A program cannot restart itself after it is closed down. I suggest a
parent program that runs the one that you want to have running. Then,
when the child program ends, the parent can restart it.

Caveat: Make sure that there is a way to end it. You do not want it to
turn into a "never-ending story."
--
Posted via http://www.ruby-....

Tim Pease

9/16/2007 7:21:00 PM

0

On 9/15/07, Michael Linfield <globyy3000@hotmail.com> wrote:
> i want to have a program restart when its closed via the X button on the
> window / terminal
>
> any ideas?
> --
> Posted via http://www.ruby-....
>

at_exit {exec "ruby", $0, *ARGS}

Should work on all platforms, but you will not get the original flags
to the ruby interpreter. You should register a signal handler to trap
SIGKILL or SIGTERM and do an exit! from the handler. This will prevent
the at_exit blocks from running.

Blessings,
TwP

RubyTalk@gmail.com

9/17/2007 4:10:00 AM

0

END{
code
}

"Declares code to be called at the end of the program (when the
interpreter quits)."

Ruby In A Nutshell: page 29.

I do have the first edition so could have changed.

SbeckerIV

On 9/16/07, Tim Pease <tim.pease@gmail.com> wrote:
> On 9/15/07, Michael Linfield <globyy3000@hotmail.com> wrote:
> > i want to have a program restart when its closed via the X button on the
> > window / terminal
> >
> > any ideas?
> > --
> > Posted via http://www.ruby-....
> >
>
> at_exit {exec "ruby", $0, *ARGS}
>
> Should work on all platforms, but you will not get the original flags
> to the ruby interpreter. You should register a signal handler to trap
> SIGKILL or SIGTERM and do an exit! from the handler. This will prevent
> the at_exit blocks from running.
>
> Blessings,
> TwP
>
>

Michael Linfield

9/17/2007 8:12:00 PM

0

John Joyce wrote:

> You're going into very platform specific territory there. Potentially
> malware like behavior.

this is true, i do see how it could be seen as malware behavior and i
should probably stay away from that. Its purpose is to make sure the
user cannot exit while its running its given functions, if they were to
do this, it could cause some serious problems :(


> at_exit {exec "ruby", $0, *ARGS}
thanks Tim Pease ill look into that

>END{
> code
>}

i will give that a shot as well
--
Posted via http://www.ruby-....

Robert Klemme

9/17/2007 9:39:00 PM

0

On 17.09.2007 22:12, Michael Linfield wrote:
> John Joyce wrote:
>
>> You're going into very platform specific territory there. Potentially
>> malware like behavior.
>
> this is true, i do see how it could be seen as malware behavior and i
> should probably stay away from that. Its purpose is to make sure the
> user cannot exit while its running its given functions, if they were to
> do this, it could cause some serious problems :(
>
>
>> at_exit {exec "ruby", $0, *ARGS}
> thanks Tim Pease ill look into that
>
>> END{
>> code
>> }
>
> i will give that a shot as well

Here's another mechanism:

loop do
Process.waitpid( fork do
# your program goes here
end )
end

Kind regards

robert

Tim Pease

9/17/2007 10:25:00 PM

0

On 9/17/07, Robert Klemme <shortcutter@googlemail.com> wrote:
>
> Here's another mechanism:
>
> loop do
> Process.waitpid( fork do
> # your program goes here
> end )
> end
>

Windows is the fork nazi ... "No fork for you!"

But clever, nonetheless.

Blessings,
TwP

Robert Klemme

9/18/2007 6:57:00 AM

0

2007/9/18, Tim Pease <tim.pease@gmail.com>:
> On 9/17/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> >
> > Here's another mechanism:
> >
> > loop do
> > Process.waitpid( fork do
> > # your program goes here
> > end )
> > end
> >
>
> Windows is the fork nazi ... "No fork for you!"

$ ruby <<XXX
> 3.times do |i|
> Process.waitpid( fork { sleep 1; puts i } )
> end
> XXX
0
1
2

$ uname -a
CYGWIN_NT-5.1 padrklemme1 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin

Now someone will be telling me that I'm cheating again. ;-)

> But clever, nonetheless.

Thanks!

Kind regards

robert

Robert Klemme

9/18/2007 6:58:00 AM

0

2007/9/18, Robert Klemme <shortcutter@googlemail.com>:
> 2007/9/18, Tim Pease <tim.pease@gmail.com>:
> > On 9/17/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> > >
> > > Here's another mechanism:
> > >
> > > loop do
> > > Process.waitpid( fork do
> > > # your program goes here
> > > end )
> > > end
> > >
> >
> > Windows is the fork nazi ... "No fork for you!"

PS: since the OP mentioned X I figured he might not be on X anyway. :-))