sylvie wrote:
Hi,
I have a Perl script which runs continously and does a
FTP PUT every hour using the NET::FTP module. This
script is compiled with Perl2exe and has to run on
Windows 95/98/2000/XP. But, on some Win95 platforms,
it crashes after about one day. A Windows message box
appears telling that the program has performed an
illegal operation and when I validate the message, the
program stops.
Some debugging messages told me that it crashes in the
_store_cmd method (invoked by the Put method in
Net::FTP) when it calls $sock->write.

I would like this error not to crash the program and
not to inform the user. I've tried these eval
expressions without success (the message box still
appears):
$ret = eval '$ftp->put("putfile","/tmp/putfile")';
eval { $SIG{PIPE}='IGNORE';
$ret=$ftp->put("putfile","/tmp/putfile");};

I've also written another program in charge of
relaunching the main program when it crashes. But,
when the error occurs, the main program is still alive
until somebody validates the message box. So, the user
is informed of the crash and moreover the program is
put on standby until anybody looks at this machine.

How could I trap this error so that it is not
displayed in a message box?

Any help appreciated.

Try:

use warnings;
use Win32::API;

my $errfunc = Win32::API->new('kernel32', 'SetErrorMode', 'I', 'I');

$initial_mode = $errfunc->Call(2);
$errfunc->Call($initial_mode | 2);

eval{# Your Net::FTP code ...};

__END__

For me that suppresses the GP fault error box - though the code has been transcribed so beware of typos.

In all probability $initial_mode is 0 - in which case the second Call() achieves nothing. (It's there because Microsoft documentation recommends doing it that way - it's important if $initial_mode is not 0.)

However, even though it avoids the error box, you might find that the error still crashes the program - even if you eval{} the offending code. Not sure how to get around that or if it can even be done.
Anyway, without the error box popping up, it allows the script to crash. And then your restart script could do the rest - no human intervention required.


Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to