我已经在我的 Windows 机器上设置了本地 Perl Web 环境。我正在开发的应用程序最初来自 Linux 服务器,因此源 .pl
文件的 shebang 如下所示:
#!/usr/bin/perl
这会导致我的 Windows 开发计算机上出现以下错误:
(OS 2)The system cannot find the file specified.
Is it possible to change我的 Apache 2 conf 以便在我的 Windows 计算机上忽略 shebang?当然,我可以将 shebang 设置为 #!c:\perl\bin\perl.exe,这是显而易见的;但问题在于部署更新的文件。显然,在每次部署时都将其改回是非常不方便的。我在 Windows 7 上使用 ActivePerl。
更新:
我应该提到我需要保持 shebang这些脚本将在我们的共享托管 Linux 生产服务器上运行。如果我没有这个限制并且我不必使用 shebang,那么显而易见的答案就是不使用它。
I have set up a local Perl web environment on my Windows machine. The application I'm working on is originally from a Linux server, and so the shebang for source .pl
files look like so:
#!/usr/bin/perl
This causes the following error on my Windows dev machine:
(OS 2)The system cannot find the file specified.
Is it possible to change my Apache 2 conf so that the shebang is ignored on my Windows machine? Of course I could set the shebang to #!c:\perl\bin\perl.exe
, that much is obvious; but the problem comes to deploying the updated files. Clearly it would be very inconvenient to change this back on each deploy. I am using ActivePerl on Windows 7.
Update:
I should have mentioned that I need to keep the shebang so that the scripts will work on our shared hosting Linux production server. If I did not have this constraint and I didn't have to use the shebang, the obvious answer would be to just not use it.
发布评论
评论(8)
我在脚本中使用
#!/usr/bin/perl
并将 Windows 上的 Apache 配置为忽略 shebang 行。添加到您的
httpd.conf
并设置 Windows 注册表项,如 Apache 文档。以下是导出密钥时得到的结果:
我一直在我的 Windows 笔记本电脑上使用此设置以及 Apache 和 ActiveState Perl,以及在我的服务器上使用 ArchLinux 附带的 Apache 和 Perl 发行版。
Apache 文档(我在上面链接到)指出:
I use
#!/usr/bin/perl
in my scripts and configure Apache on Windows to ignore the shebang line. Addto your
httpd.conf
and set up the Windows Registry key as explained in the Apache docs.Here is what I get when I export the key:
I have been using this setup with Apache and ActiveState Perl on my Windows laptop and the Apache and Perl distributions that come with ArchLinux on my server.
The Apache docs (to which I linked above) state:
没有便携式 Shebang 线。即使在相同的平台和体系结构上,某人也可能将 perl 安装在不同的位置。
诀窍是不要手动安装模块和脚本。当您将所有内容打包为发行版并使用模块工具链时,shebang 行会自动修改为指向您用于安装所有内容的 perl。您不必考虑这些细节。 :)
There is no portable shebang line. Even on the same platform and architecture, someone might have installed perl is a different location.
The trick is to not install modules and scripts by hand. When you package everything as distributions and use the module toolchain, the shebang lines are modified automatically to point to the perl you used to install everything. You shouldn't have to think about these details. :)
我使用
#!/usr/bin/env perl
作为所有 Perl 的 shebang,无论是在 *nix 还是 Windows 上。 Windows 只是忽略它,而 Unix 则遵循env
到所选的 Perl 发行版。I use
#!/usr/bin/env perl
as the shebang on all of my Perl, whether on *nix or Windows. Windows just ignores it, and Unix followsenv
to the chosen Perl disto.在 win7 及更高版本中,您还可以使用“dos”命令 mklink 来执行此操作。
以管理员身份启动 cmd shell 并执行如下操作:
In win7 and up you can also do this with the "dos" command mklink.
Start a cmd shell as administrator and do something like the following:
创建一个简单的重定向 shell 脚本:
<前><代码>执行“@”
创建注册表项:
(...等等。)
在您的
httpd.conf
文件中添加:Apache 现在将根据您选择的 Bash 风格给出的解释解析 Unix shebangs。这比在注册表中硬编码解释器路径提供了更多的灵活性。
Create a trivial redirecting shell script:
Create a registry entry:
(...and so on.)
Jot in your
httpd.conf
file:Apache will now resolve Unix shebangs relative to the interpretation given by your choosen Bash flavor. This gives much more flexibility than hardcoding interpreter paths in the registry.
我完成这项工作的方法是将
perl.exe
复制到c:/usr/bin/
并将其重命名为perl
(去掉代码>.exe)
The way I had this working was to copy
perl.exe
toc:/usr/bin/
and rename it toperl
(strip the.exe
)我手头没有 Windows,但 perlcritic 说:
所以,我猜
#! perl 应该可以工作。
编辑:在linux上不起作用;显然在
parrot
中有效,尽管我不明白他们是如何做到这一点的。I don't have Windows handy, but perlcritic says:
So, I guess
#! perl
should work.Edit: doesn't work on linux; apparently works in
parrot
, although I don't see how they manage that.在 Windows 10 中的本地主机上使用 {site-name} 运行基于 Perl 的网站时,如何使用 Linux shebang (#!/usr/bin/perl)?
这对我有用:
在默认配置中,您必须使用此shebang:
是否可以将目录(在-I开关之后)永久包含到@INC?
是的,您可以通过设置 PERLLIB 或 PERL5LIB 环境变量来做到这一点。这在从命令行运行 perl 脚本时有效,但令人惊讶的是它被 XAMPP 中的 apache 服务器忽略。然而,@INC 目录之一 (C:/Perl/perl/site/lib) 通常是空的,因此您可以创建指向网站目录的符号链接:
现在,您可以使用这个 shebang:
此外,您可以创建目录 c: \usr\bin
并从 C:\perl\perl\bin\ 复制 perl.exe
(由于某些原因,另一个 mklink 技巧在这里不起作用。)
最后,您可以在 Windows 上使用 Unix 风格的 shebang:
How to use Linux shebang (#!/usr/bin/perl) when running Perl based web-site with {site-name} on localhost in Windows 10?
This works for me:
In default configuration you must use this shebang:
Is it possible to include directory (after -I switch) permanently to @INC?
Yes, you can do it by setting the PERLLIB or PERL5LIB environment variables. This works when running perl script from command line, but surprisingly it is ignored by apache server in XAMPP. However one of @INC directories (C:/Perl/perl/site/lib) is usually empty so you can make symbolic link to your web-site directory:
Now, you can use this shebang:
Moreover, you can create directory c:\usr\bin
and copy perl.exe from C:\perl\perl\bin\
(Another mklink trick is not working here from some reasons.)
Finally, you can use Unix-styled shebang on Windows: