从 Perl 打开本地网页

发布于 2024-11-26 09:48:40 字数 131 浏览 0 评论 0原文

我正在编写一个创建 HTML 输出的 Perl 脚本,我希望在用户首选的浏览器中打开它。有没有好的方法可以做到这一点?我看不到使用 ShellExecute 的方法,因为我没有 http: 地址。

I'm writing a Perl script that creates HTML output and I would like to have it open in the user's preferred browser. Is there a good way to do this? I can't see a way of using ShellExecute since I don't have an http: address for it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱给你人给你 2024-12-03 09:48:40

假设您将输出保存到“../data/index.html”,

$ret = system( 'start ..\data\index.html' );

应该在默认浏览器中打开该文件。

添加:

此处的建议

my $filename = "/xyzzy.html";  #whatever
system("start file://$filename");

Assuming you saved your output to "../data/index.html",

$ret = system( 'start ..\data\index.html' );

should open the file in the default browser.

Added:

Advice here:

my $filename = "/xyzzy.html";  #whatever
system("start file://$filename");
情释 2024-12-03 09:48:40

如果我明白你想要做什么,这是行不通的。您必须设置一个 Web 服务器,例如 apache 并配置它来执行您的脚本。如果您以前从未这样做过,这将不是一项微不足道的任务。

If I understand what you're trying to do, this will not work. You would have to setup a web server, like apache and configure it to execute your script. This wouldn't be a trivial task if you've never done it before.

风筝有风,海豚有海 2024-12-03 09:48:40

由于这是 Windows,最简单的选择是使用 File::Temp 将数据转储到临时文件(确保其扩展名为 .htm 或 .html,并且不会被清除)立即退出脚本,以便保留文件,即您可能需要类似 File::Temp->new(UNLINK => 0, SUFFIX => '.htm')) 。那么您应该能够使用 Win32::FileOpShellExecute 定期打开该文件。这确实对与文件扩展名相关联的文件类型做出了各种假设,但这就是 Windows 的工作方式。

Since this is Windows, the easy option is to dump the data to a temporary file using File::Temp (making sure it has an extension .htm or .html, and that it isn't cleaned up immediately on script exit, so that the file remains, i.e, you probably want something like File::Temp->new(UNLINK => 0, SUFFIX => '.htm')). Then you ought to be able to use Win32::FileOp's ShellExecute to open the file regularly. This does make all sorts of assumptions about file types being associated with file extensions, but then, that's how Windows tends to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文