如何使用 Strawberry Perl 运行程序?
一位同事正尝试在他的 Windows 计算机上使用 ack (一个 Perl 程序),在 Linux 下尝试过并决定他绝对想要使用它。 他设法在他的机器上安装了 Strawberry Perl,但似乎不知道如何进行确认从命令提示符运行它。 他尝试编辑#! 线,但我知道那行不通。 我很确定 Strawberry Perl 就在他的路径中。
使用 Strawberry 在 Windows 上的 PATH 中运行通用 Perl 程序需要做什么?
更新:我在网上看到一些有关 PATHEXT 变量的信息,但还不够。
A coworker is trying to use ack (a Perl program) on his Windows machine, having tried it under Linux and decided he definitely wants to use it. He managed to get Strawberry Perl installed on his machine, but can't seem to figure out what to do to make ack run with it from a command prompt. He tried editing the #! line, but I knew that wouldn't work. I'm pretty sure Strawberry perl is in his PATH.
What do you need to do to run a general Perl program in your PATH on Windows using Strawberry?
Update: I'm seeing some information online about the PATHEXT variable, but not enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,请注意该程序位于
Path
中,而不仅仅是perl.exe
中。 Perl 二进制文件和核心程序通常最终位于\bin
中,但其他程序可能最终位于站点特定目录\site\bin
中。 该命令可能会帮助您进行搜索。 确保您的
路径
反映了您的设置。至少据我所知,有两种常见方法可以从 Windows 命令提示符运行 Perl 程序。
第一个是使用 创建程序的批处理版本pl2bat,它将使用程序执行
perl
。 安装的程序通常会自动执行此操作,因为MakeMaker
和Module::Build
会处理此操作。第二个是创建
.pl
文件关联。 这是通过创建注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command
(如果仅适用于当前用户,则创建HKEY_CURRENT_USER
)并设置(默认)
值这样,您只需使用
.pl
扩展名命名程序即可调用程序。 现在您可以使用program.pl
调用该程序。您可能已经注意到,您可以在 Windows 上调用不带扩展名的程序。 在
Path
中搜索程序,但是当没有扩展名时,使用PATHEXT
来完成名称。 将.pl
追加到列表中,您只需使用program
即可调用该程序。 请注意,此列表中的顺序对于搜索很重要,就像Path
中的顺序很重要一样。安装人员通常会处理最后两个步骤,但如果您想添加自己的步骤或需要修复它,这些知识会很有用。
First, be careful that the program is in the
Path
, not justperl.exe
. The Perl binaries and core programs usually end up in<installdir>\bin
, but others may end up in the site specific directory<installdir>\site\bin
. The commandmight aid your search. Make sure your
Path
reflects your setup.There are two common ways, at least that I know of, to run a Perl program from the Windows Command Prompt.
The first is to create a batch version of the program with pl2bat, which will execute
perl
with the program. Installed programs usually do this automatically becauseMakeMaker
andModule::Build
take care of this.The second is to create a
.pl
file association. This is done by creating the registry keyHKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command
(orHKEY_CURRENT_USER
if it's for the current user only) and set the(Default)
value toThat way, you can call programs just by naming them with the
.pl
extension. Now you can invoke the program withprogram.pl
.You may have noticed that you can call a program on Windows without the extension. The program is searched for in the
Path
, but when there's no extension,PATHEXT
is used to complete the name. Append.pl
to the list, and you can invoke the program just withprogram
. Note that the order in this list is important for the search, just as the order inPath
matters.Installers usually take care of the last two steps, but this knowledge is useful if you'd like to add your own or need to fix it.
我只是安装 ack 并从命令行运行它没有遇到问题。
Strawberry Perl 安装正确吗? 你能从 cmd.exe 运行“perl”吗?
App::Ack 安装正确吗?
如果是这样,我不明白为什么你不能从命令行运行“ack”:
如果它不起作用,那么该链中的哪里被破坏了? 例如,如果您无法从命令行运行“perl”,则 Strawberry 未正确安装(或不在您的 PATH 中),您需要修复该问题。 但除此之外,ack 会使用“ack.bat”包装器安装到与“perl”相同的路径中,因此如果您可以运行“perl”,您应该也可以运行“ack”。
I haven't had a problem just installing ack and running it from the command line.
Is Strawberry Perl installed correctly? Can you run "perl" from cmd.exe?
Did App::Ack installed correctly?
If so, I don't see why you can't run "ack" from the command line:
If it isn't working, where in that chain are things broken? For example, if you can't run "perl" from the command line, then Strawberry didn't install correctly (or isn't in your PATH) and you'll need to fix that. But otherwise, ack gets installed with an "ack.bat" wrapper into the same path as "perl", so if you can run "perl" you should be able to run "ack".
另一个解决方案是使用 PAR::Packer 创建 ack.exe - 他根本不需要 Strawberry。
Another solution is to create ack.exe with PAR::Packer - he would not need Strawberry at all.
1.安装草莓perl
2.打开perl命令行
3.编写命令perl test.pl
步骤
1.Install strawberry-perl
2.Open perl Commandline
3.Write command perl test.pl
Steps