#!/usr/bin/perl -w use 5.006; use strict; use warnings; use Win32::OLE qw(EVENTS); use Time::HiRes qw(gettimeofday); Win32::OLE->Option(_Unique => 1); sub IENavigate( $ ); $| = 1; # do not buffer output my $IE; my $IETimeout = 60; my $timeAtStart; #new global var my @urls = qw( http://www.google.com http://www.cnn.com/ ); # start ie, connect to events, make IE visible, connect alarm handler $IE = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer.Application\n"; Win32::OLE->WithEvents($IE,\&IEEvent,"DWebBrowserEvents2"); $IE->{visible} = 1; $SIG{ALRM} = \&IEAlarm; # visit some URLs foreach (@urls){ print "Navigate to $_\n"; my $seconds = IENavigate( $_ ); print "took $seconds\n"; } # we're done print "Done\n"; # kill this IE $IE->Quit(); exit; # ################################################################### # sub IENavigate( $ ) { my $url = shift; my $seconds = 0; print "IENavigate $url\n"; $timeAtStart = time unless ($timeAtStart); alarm $IETimeout; $IE->navigate($url); Win32::OLE->MessageLoop(); print "Finished Blocking\n"; return; } sub IEEvent(){ my ($Obj,$Event,@Args) = @_; if (($IETimeout) && ($timeAtStart) && (time > ($timeAtStart + $IET +imeout) )) {&IEAlarm(17)}; print "IEEvent '$Event'\n"; } sub IEAlarm(){ my $sig = shift; print "IEAlarm $sig\n"; Win32::OLE->QuitMessageLoop(); }
In reply to Re^3: Win32::OLE and timeout
by puff
in thread Win32::OLE and timeout
by puff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |