简体   繁体   English

如何使用草莓 Perl 运行程序?

[英]How do I run programs with Strawberry Perl?

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.一位同事试图在他的 Windows 机器上使用ack (一个 Perl 程序),并在 Linux 下尝试过,并决定他肯定想使用它。 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.他设法在他的机器上安装了Strawberry Perl ,但似乎无法弄清楚如何从命令提示符下运行 ack 。 He tried editing the #, line.他尝试编辑#, 行。 but I knew that wouldn't work.但我知道那行不通。 I'm pretty sure Strawberry perl is in his PATH.我很确定草莓 perl 在他的路径中。

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 变量的信息,但还不够。

First, be careful that the program is in the Path , not just perl.exe .首先,注意程序在Path中,而不仅仅是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 . Perl 二进制文件和核心程序通常以<installdir>\bin结尾,但其他可能以站点特定目录<installdir>\site\bin结尾。 The command命令

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.首先是使用pl2bat创建程序的批处理版本,它将与程序一起执行perl Installed programs usually do this automatically because MakeMaker and Module::Build take care of this.已安装的程序通常会自动执行此操作,因为MakeMakerModule::Build负责此操作。

The second is to create a .pl file association.第二个是创建一个.pl文件关联。 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这是通过创建注册表项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.这样,您只需使用.pl扩展名命名程序即可调用它们。 Now you can invoke the program with program.pl .现在您可以使用program.pl调用该程序。

You may have noticed that you can call a program on Windows without the extension.您可能已经注意到,您可以在没有扩展名的情况下调用 Windows 上的程序。 The program is searched for in the Path , but when there's no extension, PATHEXT is used to complete the name.该程序在Path中搜索,但是当没有扩展名时,使用PATHEXT来完成名称。 Append .pl to the list, and you can invoke the program just with program . Append .pl到列表中,您只需使用program即可调用该程序。 Note that the order in this list is important for the search, just as the order in Path matters.请注意,此列表中的顺序对于搜索很重要,就像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.安装人员通常会处理最后两个步骤,但如果您想添加自己的步骤或需要修复它,这些知识很有用。

I haven't had a problem just installing ack and running it from the command line.我只是安装 ack 并从命令行运行它没有问题。

Is Strawberry Perl installed correctly?草莓 Perl 安装是否正确? Can you run "perl" from cmd.exe?你能从 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.例如,如果你不能从命令行运行“perl”,那么草莓没有正确安装(或者不在你的 PATH 中),你需要修复它。 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".但除此之外,ack 会使用“ack.bat”包装器安装到与“perl”相同的路径中,因此如果您可以运行“perl”,您应该能够运行“ack”。

Another solution is to create ack.exe with PAR::Packer - he would not need Strawberry at all.另一种解决方案是使用 PAR::Packer 创建 ack.exe - 他根本不需要 Strawberry。

If he's followed the directions inthis blog post , he should be alright.如果他按照这篇博文中的指示进行操作,他应该会没事的。 I haven't had to install Strawberry Perl for a while now, but IIRC, after I installed it I was able to use it just like I would if I were on a linux box.我有一段时间不需要安装 Strawberry Perl,但是 IIRC,在我安装它之后,我可以像在 linux 盒子上一样使用它。 (eg perl yourscripthere.pl ) (例如perl yourscripthere.pl

1.Install strawberry-perl 2.Open perl Commandline 3.Write command perl test.pl 1.安装strawberry-perl 2.打开perl命令行 3.编写命令perl test.pl

Steps脚步

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM