Re: Perl Windows Open a Web Browser
by Jenda (Abbot) on Apr 09, 2007 at 22:07 UTC
|
use Win32::FileOp qw(ShellExecute);
ShellExecute("http://www.perlmonks.org");
This way the page gets opened in the user's default browser.
| [reply] [d/l] |
|
|
| [reply] |
Re: Perl Windows Open a Web Browser
by Corion (Patriarch) on Apr 09, 2007 at 19:40 UTC
|
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. | [reply] [d/l] [select] |
|
|
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");
| [reply] [d/l] |
|
|
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. | [reply] [d/l] [select] |
Re: Perl Windows Open a Web Browser
by zentara (Cardinal) 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) }
| [reply] [d/l] |
|
|
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...
| [reply] |
|
|
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.
| [reply] [d/l] |
|
|
|
|
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...
| [reply] [d/l] |
A reply falls below the community's threshold of quality. You may see it by logging in. |