如何在Windows上使用ActivePerl打开浏览器到URL?

时间:2022-12-22 02:30:14

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

在Windows上的ActivePerl中,如何在某个URL上打开浏览器?

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

在Python中,有webbrowser.open(url),但我似乎无法找到Perl等价物。

3 个解决方案

#1


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.

“start”是一个Windows命令,它将使用相关程序打开参数的任何内容。因此,只要$ url看起来像一个URL(确保它以http(s)://开头),它应该启动浏览器。

#2


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.

我知道你在Windows上使用ActivePerl,但如果你想要可移植性,那么system()调用可能是错误的方法。在OS X上,您可以将“start”更改为“open”,但在许多其他系统上,您将不得不使用另一个单词,或者可能根本没有相应的命令。这种事情实际上取决于操作系统和浏览器。

#3


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

在Windows上:从现代unixen开始(也就是说,安装了xdg-utils的那些):xdg-open

#1


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.

“start”是一个Windows命令,它将使用相关程序打开参数的任何内容。因此,只要$ url看起来像一个URL(确保它以http(s)://开头),它应该启动浏览器。

#2


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.

我知道你在Windows上使用ActivePerl,但如果你想要可移植性,那么system()调用可能是错误的方法。在OS X上,您可以将“start”更改为“open”,但在许多其他系统上,您将不得不使用另一个单词,或者可能根本没有相应的命令。这种事情实际上取决于操作系统和浏览器。

#3


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

在Windows上:从现代unixen开始(也就是说,安装了xdg-utils的那些):xdg-open