如何使用 Strawberry Perl 运行程序?

发布于 2024-07-14 23:20:01 字数 408 浏览 10 评论 0原文

一位同事正尝试在他的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

菊凝晚露 2024-07-21 23:20:01

首先,请注意该程序位于 Path 中,而不仅仅是 perl.exe 中。 Perl 二进制文件和核心程序通常最终位于 \bin 中,但其他程序可能最终位于站点特定目录 \site\bin 中。 该命令

dir C:\strawberry\ack* /s

可能会帮助您进行搜索。 确保您的路径反映了您的设置。

至少据我所知,有两种常见方法可以从 Windows 命令提示符运行 Perl 程序。

第一个是使用 创建程序的批处理版本pl2bat,它将使用程序执行 perl。 安装的程序通常会自动执行此操作,因为 MakeMakerModule::Build 会处理此操作。

第二个是创建 .pl 文件关联。 这是通过创建注册表项 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command(如果仅适用于当前用户,则创建 HKEY_CURRENT_USER)并设置(默认) 值这样

"C:\strawberry\perl\bin\perl.exe" "%1" %*

,您只需使用 .pl 扩展名命名程序即可调用程序。 现在您可以使用 program.pl 调用该程序。

您可能已经注意到,您可以在 Windows 上调用不带扩展名的程序。 在Path中搜索程序,但是当没有扩展名时,使用PATHEXT来完成名称。 将.pl追加到列表中,您只需使用program即可调用该程序。 请注意,此列表中的顺序对于搜索很重要,就像 Path 中的顺序很重要一样。

安装人员通常会处理最后两个步骤,但如果您想添加自己的步骤或需要修复它,这些知识会很有用。

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

dir C:\strawberry\ack* /s

might 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 because MakeMaker and Module::Build take care of this.

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

"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.

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.

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.

懒猫 2024-07-21 23:20:01

我只是安装 ack 并从命令行运行它没有遇到问题。

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
...

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

如果是这样,我不明白为什么你不能从命令行运行“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.

如果它不起作用,那么该链中的哪里被破坏了? 例如,如果您无法从命令行运行“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?

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?

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:

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".

2024-07-21 23:20:01

另一个解决方案是使用 PAR::Packer 创建 ack.exe - 他根本不需要 Strawberry。

Another solution is to create ack.exe with PAR::Packer - he would not need Strawberry at all.

遥远的她 2024-07-21 23:20:01

1.安装草莓perl
2.打开perl命令行
3.编写命令perl test.pl

步骤

1.Install strawberry-perl
2.Open perl Commandline
3.Write command perl test.pl

Steps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文