Monday, March 28, 2011

How do you open a browser to a URL using ActivePerl on Windows?

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.

From stackoverflow
  • 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.

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

    Mathieu Longtin : 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.
  • on windows: start on modern unixen (that is to say, those with xdg-utils installed): xdg-open

0 comments:

Post a Comment