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?  

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.

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.
system('iexplorer.exe your-URL');
RG2DMAuthor Commented:

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 ?!?


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.  
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

RG2DMAuthor Commented:

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('', 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
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.
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";            
            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
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
and you are aware that your child opens 10 Explorers one after each other?
You parent loop (for(1..5)) is useless, somehow ..
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( '');

sleep 30;



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.

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
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

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
      # wait until HTML page has loaded
      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.

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

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?
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.
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

From novice to tech pro — start learning today.