如何让 Perl 脚本识别 Win32 cmd 控制台中的参数? [英] How do I make Perl scripts recognize parameters in the Win32 cmd console?

查看:18
本文介绍了如何让 Perl 脚本识别 Win32 cmd 控制台中的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Windows 环境中调用我的 Perl 脚本而不先调用 perl 时,参数不会传递给我的脚本.

When I invoke my Perl scripts in the Windows environment without invoking perl first, the parameters are not passed to my script.

例如

C:> C:my-perl-scriptsfoo.pl bar

调用 foo.pl 但不将 bar 识别为参数(@ARGV 为空).然而,

invokes foo.pl but doesn't recognize bar as a parameter (@ARGV is empty). However,

C:> perl C:my-perl-scriptsfoo.pl bar

按预期工作.

这是配置问题吗?

理想情况下,我希望能够分发一些 perl 脚本,让用户将 C:my-perl-scripts 添加到路径中,然后就可以调用 foo.pl 在运行 cmd 时从任何地方.

Ideally, I'd like to be able to distribute some perl scripts, have the user add C:my-perl-scripts to the path and then just be able to invoke foo.pl from anywhere while running cmd.

如果他们必须先指定 perl,那么他们总是必须提供完整的路径.

If they have to specify perl first, then they'll always have to give a complete path.

有什么想法或建议吗?

为了在我的系统上显示 assoc 和 ftype 是正确的,我执行了以下命令.

To show that the assoc and ftype are correct on my system, I executed the following commands.

C:>assoc .pl
.pl=Perl

C:>ftype Perl
Perl="C:Perlinperl.exe" "%1" %*

C:>more t.pl
print "'$_'
" for @ARGV;

C:>t a b

C:>perl t.pl a b
'a'
'b'

C:>t.pl a b

C:>

我同时包含了 t 和 t.pl 的输出,以表明它不是 %PATHEXT% 问题.两者都没有像最初描述的那样输出任何内容,而调用 perl 首先给出了预期的响应.

I included both the output of t and t.pl to show it's not a %PATHEXT% problem. Both outputted nothing as originally described whereas invoking perl first gave the expected response.

我不知道下一步该往哪里看,但感谢迄今为止的建议.他们非常有帮助.

I'm not sure where to look next, but thanks for the suggestions so far. They have been very helpful.

编辑 2: 问题似乎出在我的 vista 商务盒子上.在我的 xp pro 盒子上,它按预期工作.两者都有 ActivePerl 5.8.9.我还有另一个尚未尝试过的 vista home box.如果我发现任何东西,我会回帖.

Edit 2: The problem appears to be on my vista business box. On my xp pro box, it works as expected. Both have ActivePerl 5.8.9. I have another vista home box that I have not yet tried yet. I'll post back if I discover anything.

编辑 3: 我找到了答案(贴在下面).我通过运行注册表清理器,删除 perl,再次运行注册表清理器来找到它.在第二次清理时,只剩下一个无效条目 - 导致问题的条目(可能是上次安装遗留的).

Edit 3: I found the answer (posted below). I found it by running a registry cleaner, removing perl, running the registry cleaner again. On 2nd cleaning, only one invalid entry remained - the one that was causing the problem (probably left over from a previous installation).

推荐答案

我发现了问题所在.尽管按照建议设置了 ftype 和 assoc 值,但我系统上的实际行为似乎由注册表项决定

I found out what the problem was. Although the ftype and the assoc values were set as suggested, the actual behavior on my system seems to be determined by the registry key

HKEY_CLASSES_ROOTApplicationsperl.exeshellopencommand

它应该有一个 (Default) 字符串值 "C:Perlinperl.exe" "%1" %*

It should have a (Default) string value of "C:Perlinperl.exe" "%1" %*

当我找到这个条目时,它被设置为 "C:Perlinperl.exe" "%1".更改它立即解决了问题.

When I found this entry, it was set to "C:Perlinperl.exe" "%1". Changing it immediately fixed the problem.

为什么要这样设置?我不知道.也许来自以前的安装?

Why it was set that way in the first place? I don't know. Maybe from a previous installation?

无论如何,感谢您的建议,我希望这个答案也能帮助其他人.

Anyway, thanks for the suggestions, and I hope this answer helps someone else, too.

这篇关于如何让 Perl 脚本识别 Win32 cmd 控制台中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆