Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl Windows Open a Web Browser

by SteveS832001 (Sexton)
on Apr 09, 2007 at 19:27 UTC ( #609016=perlquestion: print w/ replies, xml ) Need Help??
SteveS832001 has asked for the wisdom of the Perl Monks concerning the following question:

I know that I am a loser for not looking before I ask, but I am short on time and Have many things that I need to do to get my project done. First let me give you some backgroung Info.

I was asked to create a HTML Forms Page that They want to put on jump drives. So I created the Form and a Perl Script that Processes all the information. So I setup Tinyweb on the Jump drive to have a small webserver running so that the cgi script would work. But to wrap everything up I need to create a exe with perl that Will launch the Tinyweb <--- which I can Do, But will also Launch a Web Browser to a specifiy webpage. <-- Which I need help with. Thanks a Million

Comment on Perl Windows Open a Web Browser
Re: Perl Windows Open a Web Browser
by Corion (Pope) on Apr 09, 2007 at 19:40 UTC

    The simplest way is to leave it all to Windows:

    my $url = "http://localhost:8080/"; my $commandline = qq{start "$url" "$url"}; system($commandline) == 0 or die qq{Couldn't launch '$commandline': $!/$?};

    Update: The start command was missing from the command line. Oops.

      Well I must not understand the code you wrote, but you gave me an idea So I tried this and it works fine

      $url = 'http://127.0.0.1:8000'; system("explorer $url");
        Good idea (I hope). start is a "program" that comes with Windows, and that serves to start up documents in their default program. Or, as in this case, URLs.

        But start is not trouble free, on some instances of Windows, it is not a standalone program, but a built-in in cmd, the command line interpreter. And then, this command will not work. There have been longish discussions in the Chatterbox on how you can use

        cmd /c start $url
        (IIRC) to get arround that limitation, but it appears to me that using explorer.exe to dispatch to the proper default program will work just as well. And be less of a silly hack. At least, here, it opens in MSIE7 and not in an explorer (file browse) window, I'll have to try it at home to see if it'll cooperate with Firefox too.
Re: Perl Windows Open a Web Browser
by Jenda (Abbot) on Apr 09, 2007 at 22:07 UTC

      Jenda, OMG! Why didn't I look for this simple solution sooner?! It's been in the back of my mind for a while, and your solution worked like a charm! Lovely! :)

      Have a cookie and a very nice day!
      Lady Aleena
Re: Perl Windows Open a Web Browser
by zentara (Archbishop) on Apr 10, 2007 at 10:14 UTC
    It sounds like you are on windows, but just for the sake of completeness, this works on linux.
    #!/usr/bin/perl use warnings; use strict; #my $linkurl = 'http://zentara.net'; my $linkurl = 'linux-tips.html'; my $command = "mozilla -remote \"openURL($linkurl)\""; if(fork() == 0){ exec ($command) }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      It sounds like you are on windows,

      Which bit of

      Perl Windows Open a Web Browser

      did your speech recognition software have trouble with?

        To me Windows can mean any graphical display, X or MS.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      If you have mozilla installed (unlikely), and if it's in PATH (very unlikely), then it'll probably work on Windows too. Most likely it'll even work with Firefox as the browser (though maybe under a different name).

      However, I hate programs that make assumptions on what your favourite software is (or should be, according to them). Usually, it's programs that open up HTML pages in MSIE, irrespective of what your default browser is...

        No - the Mozilla mozilla -remote thing does not work on Windows - as far as my investigations went back in the days of HTML::Display, FireFox/Mozilla do not offer any ways of remotely controlling a browser window, unlike Internet Explorer.

        The ShellExecute technique suggested by Jenda will cleanly, consistently, without hanging, cause your default browser, whatever that is, to browse to the URL you tell it. Whether it does so in a new window or existing window depends on how you configure the browser itself. Now, as for controlling that browser window afterwards, that's another story...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://609016]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-08-21 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls