using perl to open internet explorer browser

I am trying to run a script that feeds urls to a browser window, and then actually with help of ps -ef finding pid for internet explorer so I can kill it.

Any hints?  

thanks
RG2DMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmcgOwnerCommented:
I can't answer your question, but if you respond to my clarification request, some of the other experts may be able to solve it.

Normally, 'ps' is a command that is run on a UNIX or Linux system -- a place where Internet Explorer does not run. If you're on a Windows system, I believe you'd use Win32::OLE module calls to start up an instance of IE, direct it to various URLs, and finally shut it down.
0
ahoffmannCommented:
system('iexplorer.exe your-URL');
0
RG2DMAuthor Commented:
jmcg,

I actually installed mks toolkit, which lets you utilize some unix commands on a Windows machine.  ps does work, but maybe not correctly through a script ?!?

ahoffmann,

using that syntax doesn't work the way i want, because that does open a browser with the url, but the script will wait until the browser is closed before it proceeds with the rest of the script.  
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

RG2DMAuthor Commented:
jmcg,

I have uninstalled MKS Toolkit, to be able to utilize Win32::OLE properly.  
I did get a browser open by :

$browser = Win32::OLE->new('InternetExplorer.Application') or die "Can't start IE";

$browser->Navigate('http://www.google.com', 1,'_BLANK');

Now my question is, how do you close the browser?

I will increase the points, since you got me in the right direction but there is still the window to close completely
0
ahoffmannCommented:
Win32::OLE might be the M$-way to do it (I don't know)
but you may also use fork() and then start system("iexplorer.exe URL") in the child.
0
RG2DMAuthor Commented:
ok.  instead of win32::ole, I use fork.
Looking at the books that I have, and the listings I see under fork, i am confused.

Tried an example but the sequence doesn't match or makes sense.  Can you help me a little?

#! /usr/bin/perl -w

# Parent Process

print "Starting the Parent Process!\n";

unless ($pid = fork)
      {
      #Start of Child Process
      for (1..10)
            {
            system "iexplore.exe www.google.com";            
            sleep 1;
            }
            exit 0;
      }

# End of Child Process

# Continuation of Parent
for (1..5)
      {
      print "Parent, Count $_\n";
      sleep 2;
      }
      
waitpid ($pid, 0);

# End of Parent
0
turn123Commented:
You can close IE when your done with it buy calling it like this.

my $BROWSER = Win32::OLE->new('InternetExplorer.Application', 'Quit');

Taken from this post by Douglas Galbraith
http://groups.yahoo.com/group/perl-win32-users/message/24591?source=1
0
ahoffmannCommented:
and you are aware that your child opens 10 Explorers one after each other?
You parent loop (for(1..5)) is useless, somehow ..
0
jmcgOwnerCommented:
I guess the group here has fewer Windows users than I thought.

The post that Turn123 pointed you to has the elements that I expected would be the way to do what you want, thought the one line he quoted is only sufficient to get a handle on a not-yet-displayed InternetExplorer window. It's a start, not an end.

So the sequence I just tested out with ActivePerl looks like this:

use Win32::OLE;
use Win32::OLE::Const;

my $Browser = Win32::OLE->new( 'InternetExplorer.Application', 'Quit');
$Browser->{'Visible'} = 1;
$Browser->Navigate( 'http://www.experts-exchange.com/');

sleep 30;

$Browser->Quit;

===============

You can test the $Browser->{Busy} flag to check whether it has finished retrieving and displaying the latest Navigate command.

I think I have a use for this code already. I'm so glad you asked this question and that Turn123 has pointed at such a valuable answer.

Ahoffman's fork suggestion is another way to go, but I think it limits you to sending a kill signal to the $pid of the child process as a way of stopping the process.

0
ahoffmannCommented:
as said, I only know perl, not M$, but I believe in perl's modules and if there is one for M$ it might be a better solution than using traditional fork()
I'm learning too, so I keep jmcg's sample
;-)
0
turn123Commented:
I finished the script I was working on when I found the answer on how to close it and will post it here.

It works on my XP computer.

It is a package so you would need to add this line in the calling script "require orders::webfetch;"
To get a value you would need to set $site to your website and $visible to 0 to hide or 1 to see IExplorer.

I named it webfetch.pm

It is called like this.  my $rawdata = orders::webfetch::fetch ($site, $visible);

##      This opens a Internet Explorer window, downloads the contents, then closes it.

use Win32::OLE;
use Win32::OLE::Const;
package orders::webfetch;
sub fetch {
      my $BROWSER = Win32::OLE->new('InternetExplorer.Application', 'QUIT');
      # access the web site
      $BROWSER->{'Visible'}=$_[1];
      $BROWSER->Navigate("$_[0]");
      
      # wait until HTML page has loaded
      do
      {
            sleep(1);
            $stat=$BROWSER->{Busy};
      }
      while ($stat);

      # get the HTML page from the browser
      my $body=$BROWSER->Document->{body};
      my $html = $body->{innerHTML};
      
      return $html;
}

return 1;

I hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmcgOwnerCommented:
Turn123,

Is there a reason you're using IE to fetch rather than fetching the HTML directly with LWP?

You're not calling $BROWSER->Quit in your routine, so I assume that the IE process goes away when your sub returns and the $BROWSER object goes out-of-scope?
0
turn123Commented:
I'm logging into a site that uses an SSL connection and requires a username and password so this was the eaisest way I found to do it.

I'm not sure about $BROWSER->Quit and didn't think about it.  I've added it.  Thanks for pointing it out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.