PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > loop a program on exit?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
loop a program on exit?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/09/2007, 06h51   #1
Michael Linfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut loop a program on exit?

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-forum.com/.

  Réponse avec citation
Vieux 16/09/2007, 15h40   #2
John Joyce
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?


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-forum.com/.
>

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.

  Réponse avec citation
Vieux 16/09/2007, 19h04   #3
Lloyd Linklater
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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-forum.com/.

  Réponse avec citation
Vieux 16/09/2007, 20h20   #4
Tim Pease
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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-forum.com/.
>


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

  Réponse avec citation
Vieux 17/09/2007, 05h10   #5
RubyTalk@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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-forum.com/.
> >

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


  Réponse avec citation
Vieux 17/09/2007, 21h12   #6
Michael Linfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 22h38   #7
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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
  Réponse avec citation
Vieux 17/09/2007, 23h24   #8
Tim Pease
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: loop a program on exit?

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h47.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11229 seconds with 16 queries