突然之间,perl 脚本无法工作,除非我在它们前面加上“perl”前缀。并给出脚本的完整路径

发布于 2024-11-09 19:01:53 字数 1005 浏览 0 评论 0原文

我一直在使用我自己的个人环境,该环境已经运行了 20 多年。大约 14 年前,我开始合并许多 Perl 脚本。 22 年来我一直在使用同一棵命令行解释器(NDOS->4DOS->4NT->TCMD,实际上都是相同的程序)。

我刚刚从 ActiveState windows perl 切换到 Strawberry Perl。

多年来,这就是我运行 perl 脚本所需的一切:

SET .pl=perl

这就是指定使用什么程序打开内容的方式。

我可以简单地做到这一点:

c:\>test.pl
Hello, world!

一切正常。永远。

今天,在一个使用了一周的操作系统中,一切都停止了。

Perl 脚本将运行,但它们不会执行任何操作。没有错误。无输出。没有什么。

它起作用的唯一方法是如果我在脚本前加上“perl”前缀(在这种情况下,不会搜索我的路径,因为脚本名称现在是一个参数,所以我必须填写脚本的完整路径)

这就是我的感受:

C:\>test.pl

C:\>perl test.pl 
Can't open perl script "test.pl": No such file or directory

C:\>perl c:\bat\test.pl 
Hello, world!

请注意,昨天甚至今天早些时候都运行良好。我不知道是什么改变了它,是什么破坏了它,我已经看了很长时间,发现了类似但不相同的问题 - 并且没有任何修复可以帮助。

我有一大堆脚本。我真的很讨厌必须在每一个之前插入世界“perl”,然后限定完整路径!

实际上,我可能需要编写一个 perl.bat 包装器,将参数文件名转换为完全限定的路径,并显式调用 perl。

我真的不想那样做。这是一个禁令援助解决方案。我想了解问题出在哪里,解决问题并解决它。

我开始讨厌Windows 7了...

I've been using my own personal environment that's worked consistently for over 20 years. I started incorporating many perl scripts about 14 years ago.
I've been using the same tree of command-line interpreters for 22 yrs (NDOS->4DOS->4NT->TCMD, all the same program really).

I just switched from ActiveState windows perl to Strawberry Perl.

For years, this is all I've needed to run a perl script:

SET .pl=perl

This is how you specify what program to open things with.

this I can simply do:

c:\>test.pl
Hello, world!

Things just worked. Forever.

Today, in a week-old OS, things just stopped working.

Perl scripts will run, but they won't DO anything. No error. No output. Nothing.

The only way it works is if I prefix the script with "perl" (in which case, my path isn't searched because script name is now a parameter, so I'm left having to fill in the full path for the script)

Here's what it's like to be me:

C:\>test.pl

C:\>perl test.pl 
Can't open perl script "test.pl": No such file or directory

C:\>perl c:\bat\test.pl 
Hello, world!

Note that this was working fine yesterday, even earlier today. I don't know what changed this and what broke it, and I've looked quite a long time, found similar but not identical issues - and no fix has helped.

I hvae a boatload of scripts. I would really hate to have to insert the world "perl" before every one of them, and then qualify the full path!

Realistically, I will probably have to write a perl.bat wrapper that converts the parameter filename into a fully qualified path, and explicitly calls perl.

I really don't want to do that. That's a ban-aid solution. I want to understand what is wrong, address is, and resolve it.

I'm starting to hate Windows 7...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

不爱素颜 2024-11-16 19:01:53

我认为您的问题很可能是 .pl 与 perl.exe 的关联被破坏。

查看注册表中的 HKEY_CLASSES_ROOT\.pl,它下面可能有 Perl(或 FOO)子节点

现在查看 HKEY_CLASSES_ROOT\Perl 或 FOO,如果是这样的话。

它应该有一个 shell\Open\command

,看起来应该像这样

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

当然,您系统上的 perl.exe 路径可能会有所不同。 %* 是将您传递给脚本的参数传递给 perl.exe 的重要位,

因此当您在命令窗口中执行“test.pl foo bar”时,幕后的 shell 是实际调用

C:\perlpath\perl.exe C:\scriptpath\test.pl foo bar.

当您简单地在 Windows 资源管理器中选择一个 *.pl 文件并尝试将其与 perl.exe 关联时,就会发生此类问题。

作为额外的好处,如果将 .PL 添加到 PATHEXT 环境变量,您甚至不必指定 test.pl,只需 test 将调用 test.pl(如果它位于路径中的第一个:)

I think your problem is most likely that association to .pl to perl.exe is broken.

Look at HKEY_CLASSES_ROOT\.pl in registry it probably has Perl(or say FOO) subnode under it

Now look at HKEY_CLASSES_ROOT\Perl or FOO if that is the case.

It should have a shell\Open\command key

which should look something like this

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

Of course the perl.exe path on your system might be different. The %* is the important bit which passes the arguments that you pass to your script to perl.exe

So when you do "test.pl foo bar" in a command window, the shell behind the scenes is actually invoking

C:\perlpath\perl.exe C:\scriptpath\test.pl foo bar.

This sort of problem happens when you simply pick a *.pl file in the windows explorer and try to associate it with perl.exe.

As a added bonus, If you add .PL to PATHEXT enviroment variable you even don't have to specify test.pl simply test will invoke test.pl if it is first in the path :)

×纯※雪 2024-11-16 19:01:53

Windows Powershell

在 Windows Powershell 中,将 .PL 添加到 PATHEXT 环境变量(否则脚本将在单独的 CMD 窗口中运行)。

但是,Powershell 不会运行命令,除非它们位于 PATH 中(即默认情况下“.”不在 $env:PATH 中,有点像 Unix 上的 root)。

因此,运行脚本

./script 
./script.pl

最简单的方法是使用 Powershell 配置文件。

例如,在 C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 中,

$env:PATH   = "C:\strawberry\perl\bin;$env:PATH"
$env:PATHEXT    = "$env:PATHEXT;.PL"

如果您不想执行 ./ (请注意,这是一个安全风险),请添加“.”到路径(不带引号)

$env:PATH   = "C:\strawberry\perl\bin;$env:PATH;."

然后你可以这样做

script

Windows Powershell

In Windows Powershell, add .PL to the PATHEXT environment variable (otherwise the script will run in a separate CMD window).

However, Powershell will not run commands unless they are in PATH (i.e. "." is not in $env:PATH by default, a bit like root on Unix)

So, to run a script

./script 
./script.pl

Easiest way is to use the Powershell profile.

e.g. in C:\Users\username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

$env:PATH   = "C:\strawberry\perl\bin;$env:PATH"
$env:PATHEXT    = "$env:PATHEXT;.PL"

If you want to not have to do ./ (and note, this is a security risk), add "." to the path (without the quotes)

$env:PATH   = "C:\strawberry\perl\bin;$env:PATH;."

Then you can just do

script
一萌ing 2024-11-16 19:01:53

您可以通过右键单击.pl文件,选择属性,然后单击“打开方式”按钮来检查文件扩展名关联(这是XP,我不知道它在 Windows 7 中的外观)。您的扩展程序可能指向错误的位置。

You can check your file extension association by right clicking a .pl file, select properties, and click the "open with" button (this is XP, I don't know how it looks in Windows 7). It may be that your extension is pointing to the wrong place.

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