nisha has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks, I would like to know how to launch internet explorer using a perl script. Please help me! Thanks, Nisha

Replies are listed 'Best First'.
Re: Launching Internet Explorer
by Arunbear (Prior) on Sep 26, 2006 at 12:24 UTC
    Try Win32::IE::Mechanize e.g. :
    use strict; use warnings; use Win32::IE::Mechanize; my $IE = Win32::IE::Mechanize->new( visible => 1 ); $IE->get("http://perl.com");
Re: Launching Internet Explorer
by cdarke (Prior) on Sep 26, 2006 at 12:26 UTC
Re: Launching Internet Explorer
by liverpole (Monsignor) on Sep 26, 2006 at 12:32 UTC
    Hi nisha,

    A simple example, using good 'ol system:

    #!/usr/bin/perl -w use Win32; use strict; use warnings; my $link = "http://www.perlmonks.com"; my $ie = '"C:\\Program Files\\Internet Explorer\\iexplore.exe"'; system("$ie $link");

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

      It's safer to avoid the shell.

      my $link = 'http://www.perlmonks.org/'; my $ie = 'C:\\Program Files\\Internet Explorer\\iexplore.exe'; system($ie, $link);

      Use start to use the user's prefered browser.

      my $link = 'http://www.perlmonks.org/'; system('start', $link);
        Defying the spirit of safety, using "start" will introduce the evil shell again:
        D:\temp>perl my $link = '"http://perlmonks.org/" & echo Oops!'; system('start', $link); ^Z Oops!
        ikegami, granted that your method works.  But it's a wee bit vague just to say it's safer to avoid the shell.  Could you be so kind as to explain why it's safer?

        Thanks for the information about "start"; that seems quite useful.


        s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Launching Internet Explorer
by pKai (Priest) on Sep 27, 2006 at 11:51 UTC

    For launching IEs as sort of "poor man's explorer" in RUNAS-Dosboxes (IE will inherit credentials, while explorer won't), I use the following 1-line-batch

    perl -MFile::Spec::Functions -MCwd -MProc::Background -e "my $a=qq(@ARGV);$a = catfile(getcwd,$a) if $a!~/[\\\/]/;Proc::Background->new('C:\Program Files\Internet Explorer\IEXPLORE.EXE',$a)" %*

    Proc::Background just serves as wrapper to Win32::Process to simplify the interface.

    Using an applicable form of system as described above is of course a viable alternative.