Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32::OLE: launch IE and _keep_it_running_ after exiting script

3 views
Skip to first unread message

A. Farber

unread,
Aug 28, 2003, 11:29:28 AM8/28/03
to
Hi,

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

Bob Walton

unread,
Aug 28, 2003, 5:08:16 PM8/28/03
to
A. Farber wrote:

...


> 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

James Willmore

unread,
Aug 28, 2003, 7:39:01 PM8/28/03
to
"A. Farber" <Alexande...@nokia.com> wrote in message news:<3F4E223E...@nokia.com>...

> 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');

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

A. Farber

unread,
Aug 29, 2003, 4:23:46 AM8/29/03
to
Bob Walton wrote:

> A. Farber wrote:
> >
> > 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;

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

Jay Tilton

unread,
Aug 29, 2003, 6:05:21 PM8/29/03
to
"A. Farber" <Alexande...@nokia.com> wrote:

: 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;
}

0 new messages