views:

222

answers:

3

In ActivePerl on Windows, how do I open a browser to some URL?

In Python, there is webbrowser.open(url), but I can't seem to find the Perl equivalent.

+4  A: 

Not sure if there's a "right" way to do it, but this should work:

my @command = ('start', $url);
system(@command);

"start" is a windows command that will use whatever the associated program is to open the argument. So as long as $url looks like a URL (make sure it starts with http(s)://), it should start up the browser.

Chad Birch
+1  A: 

I know you're using ActivePerl on Windows, but if you want portability then a system() call is probably the wrong way to go. On OS X, you could change 'start' to 'open', but on many other systems you'll have to use another word, or may not have an equivalent command at all. This kind of thing is really OS- and browser-dependent.

Chris Lutz
Well, the version that is going to run on windows will be using a system tray icon and Activestate's PDK, so that part would need a rewrite for unixes anyway.
Mathieu Longtin
A: 

on windows: start on modern unixen (that is to say, those with xdg-utils installed): xdg-open

MkV