I'm using ActivePerl 5.8.0 build 806 on Windows 2000.
The following script does launch the web browser,
but when the script exits after 10 seconds, the web
browser disappears too. Could someone please advise
me, what to do in order to keep the web browser running
even after the script which had launched it has quit?
use strict;
use Win32::OLE;
my ($ie, $url);
$url = 'http://www.perl.com';
$ie = Win32::OLE->new('InternetExplorer.Application', 'Quit');
unless ($ie) {
print "Please open a web browser and type in the following url:\n$url\n";
} else {
$ie->Navigate($url);
$ie->{Visible} = 1;
}
# Some code here
sleep 10;
Regards
Alex
...
> I'm using ActivePerl 5.8.0 build 806 on Windows 2000.
>
> The following script does launch the web browser,
> but when the script exits after 10 seconds, the web
> browser disappears too. Could someone please advise
> me, what to do in order to keep the web browser running
> even after the script which had launched it has quit?
>
> use strict;
> use Win32::OLE;
> my ($ie, $url);
>
> $url = 'http://www.perl.com';
> $ie = Win32::OLE->new('InternetExplorer.Application', 'Quit');
remove this----------------------------------------------^^^^^^^^
and it won't quit when your Perl program exits.
> unless ($ie) {
> print "Please open a web browser and type in the following url:\n$url\n";
> } else {
> $ie->Navigate($url);
> $ie->{Visible} = 1;
> }
>
> # Some code here
> sleep 10;
...
> Alex
--
Bob Walton
Change to:
$ie = Win32::OLE->new('InternetExplorer.Application', 'Open');
Because you're telling the application to 'Quit' (at least, that's my
read on it), it's going to , well, quit when the script exits. I
tried it with 'Open' and all appeared to be okay. I also tried it
without the sleep, and all seemed okay.
HTH
Jim
thank you Bob, it works now! One more question: is it possible for my
script to be notified when the launched browser gets closed by the user?
The problem is, that after I launch the browser, I'm waiting for
a connection from the mod_perl script, that the browser loads:
$select = IO::Select->new($server);
if ($select->can_read(TIMEOUT)) {
if ($webscript = $server->accept()) {
$webscript->timeout(TIMEOUT);
# Copy everything received from WEBHOST to CCM GUI
print "MSG:$_" while <$webscript>;
}
$webscript->close();
} else {
print STDERR "accept failed\n";
}
} else {
print STDERR "select failed\n";
}
$server->close();
However I'd like to quit if the user decides to close the browser
and thus to skip connecting to my "mini-server". I'm rereading
Win32::OLE documentation but don't see a way to implement that yet.
Regards
Alex
: thnak you Bob, it works now. One more question: is it possible for my
: script to be notified when the launched browser gets closed by the user?
Not exactly. The OnQuit event would be triggered when the browser is
closed, but Win32::OLE does not support events.
As a workaround, you can check whether the IE object has been closed
before doing something that requires it to be open.
my $ie = Win32::OLE->new('InternetExplorer.Application');
$ie->{Visible} = 1;
while(1) {
die "Hey! You closed my IE window!\n"
unless defined $ie->ReadyState;
print "I'm busy. Go away.\n";
sleep 1;
}