从 Perl 打开本地网页
我正在编写一个创建 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您将输出保存到“../data/index.html”,
应该在默认浏览器中打开该文件。
添加:
此处的建议:
Assuming you saved your output to "../data/index.html",
should open the file in the default browser.
Added:
Advice here:
如果我明白你想要做什么,这是行不通的。您必须设置一个 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.
由于这是 Windows,最简单的选择是使用
File::Temp
将数据转储到临时文件(确保其扩展名为 .htm 或 .html,并且不会被清除)立即退出脚本,以便保留文件,即您可能需要类似File::Temp->new(UNLINK => 0, SUFFIX => '.htm')
) 。那么您应该能够使用Win32::FileOp
的ShellExecute
定期打开该文件。这确实对与文件扩展名相关联的文件类型做出了各种假设,但这就是 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 likeFile::Temp->new(UNLINK => 0, SUFFIX => '.htm')
). Then you ought to be able to useWin32::FileOp
'sShellExecute
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.