newrisedesigns has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that I would like to have automatically restart when a die() occurs.
When I use the following code, if spits out some junk (represented as some unicode characters) when it dies. It only does this the first time. Every observed restart/die is does so cleanly without those characters.
I'm concerned that this "junk" might cause my looping program (a Net::FTP download script) to end and not restart. Do you see this as a concern, and if so, any clue why it's dumping garbage the first time around?
#!/usr/bin/perl -w $SIG{__DIE__} = \&restart; print "Dying!\n"; sleep(5); die($!); sub restart{ print "Restart...\n\n"; exec($0); } __END__ D:\projects\test>dietest.pl Dying! Restart... ??D:\projects\test>Dying! Restart... Dying! Restart... Dying!
Now that I think of it... is this the best way to restart a dying program? Is there some cleaner/more reliable method?
Thanks in advance,
John J Reiser
newrisedesigns.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with using $SIG{__DIE__} to restart program
by bluto (Curate) on Oct 24, 2002 at 17:06 UTC | |
|
Re: Problem with using $SIG{__DIE__} to restart program
by fglock (Vicar) on Oct 24, 2002 at 17:19 UTC |