windows 如何使用 Strawberry Perl 运行程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/667471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I run programs with Strawberry Perl?
提问by skiphoppy
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 Perlinstalled 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.
一位同事试图在他的 Windows 机器上使用ack(一个 Perl 程序),在 Linux 下尝试过它并决定他肯定要使用它。他设法在他的机器上安装了Strawberry Perl,但似乎无法弄清楚如何从命令提示符运行 ack。他尝试编辑 #! 行,但我知道那行不通。我很确定 Strawberry perl 在他的 PATH 中。
What do you need to do to run a general Perl program in your PATH on Windows using Strawberry?
您需要做什么才能使用 Strawberry 在 Windows 上的 PATH 中运行通用 Perl 程序?
Update: I'm seeing some information online about the PATHEXT variable, but not enough.
更新:我在网上看到一些关于 PATHEXT 变量的信息,但还不够。
采纳答案by Ronald Blaschke
First, be careful that the program is in the Path
, not just perl.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 command
首先,请注意该程序Path
位于perl.exe
. Perl的二进制文件和核心程序通常在结束了<installdir>\bin
,但其他人可能在站点特定目录中结束<installdir>\site\bin
。命令
dir C:\strawberry\ack* /s
might aid your search. Make sure your Path
reflects your setup.
可能有助于您的搜索。确保您Path
反映了您的设置。
There are two common ways, at least that I know of, to run a Perl program from the Windows Command Prompt.
从 Windows 命令提示符运行 Perl 程序有两种常用方法,至少我知道是这样。
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 because MakeMaker
and Module::Build
take care of this.
第一种是使用pl2bat创建程序的批处理版本,它将perl
与程序一起执行。已安装的程序通常会自动执行此操作,因为MakeMaker
并Module::Build
会处理此问题。
The second is to create a .pl
file association. This is done by creating the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command
(or HKEY_CURRENT_USER
if it's for the current user only) and set the (Default)
value to
二是创建.pl
文件关联。这是通过创建注册表项HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command
(或者HKEY_CURRENT_USER
如果它仅用于当前用户)并将(Default)
值设置为
"C:\strawberry\perl\bin\perl.exe" "%1" %*
That way, you can call programs just by naming them with the .pl
extension. Now you can invoke the program with program.pl
.
这样,您只需使用.pl
扩展名命名程序即可调用程序。现在您可以使用program.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 with program
. Note that the order in this list is important for the search, just as the order in Path
matters.
您可能已经注意到,您可以在没有扩展名的情况下调用 Windows 上的程序。该程序在 中搜索Path
,但在没有扩展名时,PATHEXT
用于补全名称。附加.pl
到列表中,您只需使用program
. 请注意,此列表中的顺序对于搜索很重要,就像顺序很重要一样Path
。
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.
安装程序通常会处理最后两个步骤,但是如果您想添加自己的或需要修复它,这些知识非常有用。
回答by xdg
I haven't had a problem just installing ack and running it from the command line.
我没有遇到问题,只是安装 ack 并从命令行运行它。
Is Strawberry Perl installed correctly? Can you run "perl" from cmd.exe?
Strawberry Perl 是否正确安装?你能从 cmd.exe 运行“perl”吗?
C:\> perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
...
Did App::Ack installed correctly?
App::Ack 是否正确安装?
C:\> cpan App::Ack
...
Installing C:\strawberry\perl\site\lib\App\Ack.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Plugin.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Repository.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Resource.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Plugin\Basic.pm
Installing C:\strawberry\perl\bin\ack
Installing C:\strawberry\perl\bin\ack.bat
Writing C:\strawberry\perl\site\lib\auto\ack\.packlist
Appending installation info to C:\strawberry\perl\lib/perllocal.pod
PETDANCE/ack-1.88.tar.gz
C:\strawberry\c\bin\dmake.EXE install UNINST=1 -- OK
If so, I don't see why you can't run "ack" from the command line:
如果是这样,我不明白为什么您不能从命令行运行“ack”:
C:\> ack --version
ack 1.88
Copyright 2005-2009 Andy Lester, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
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".
如果它不起作用,那么链条中的哪个地方坏了?例如,如果您无法从命令行运行“perl”,那么 Strawberry 没有正确安装(或不在您的 PATH 中),您需要修复它。但除此之外,ack 会使用“ack.bat”包装器安装到与“perl”相同的路径中,因此如果您可以运行“perl”,您应该能够运行“ack”。
回答by Alexandr Ciornii
Another solution is to create ack.exe with PAR::Packer - he would not need Strawberry at all.
另一种解决方案是使用 PAR::Packer 创建 ack.exe - 他根本不需要 Strawberry。