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

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

问题描述

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



例如,

  C:\> C:\my-perl-scripts\foo.pl bar 

调用 foo.pl ,但不能识别 bar 作为参数( @ARGV 空)。但是,

  C:\> perl C:\ my-perl-scripts \foo.pl bar 

/ p>

这是一个配置问题吗?



理想情况下,我想能够分发一些perl脚本,让用户在路径中添加 C:\my-perl-scripts \ ,然后只需调用 foo.pl

如果他们必须首先指定perl,那么他们总是必须给出一个完整的路径。



任何想法或建议?



编辑:显示我的assoc和ftype系统,我执行了以下命令。

  C:\> assoc .pl 
.pl = Perl

C:\> ftype Perl
Perl =C:\Perl\bin\perl.exe%1%*

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

C:\>标签

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

C:\> t.pl ab

C:\>

我包括t和t.pl的输出,表明它不是%PATHEXT%问题。两个输出什么都不像最初描述的,而调用perl首先给出了预期的响应。



我不知道在哪里看下,但感谢到目前为止的建议。他们一直非常有帮助。



编辑2:问题似乎在我的vista商务框中。在我的xp pro框,它的工作原理。两者都有ActivePerl 5.8.9。我有另一个远景家庭框,我还没有尝试过。



编辑3:我找到了答案(见下文)。我发现它通过运行注册表清理,删除perl,再次运行注册表清理。在第二次清理时,只剩下一个无效输入 - 导致问题的输入(可能是上次安装时遗留的输入)。

解决方案

我发现了什么问题。虽然ftype和assoc值设置为建议,我的系统上的实际行为似乎是由注册表项确定

  HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command 

(默认值) 的字符串值C:\Perl\bin\\\\\\\\\\\\\\\\\\\\\\\\\\ c $ c>



当我找到这个条目时,它被设置为C:\Perl\bin\perl.exe %1。改变它立即解决了问题。



为什么会这样设置?我不知道。也许从以前的安装?



无论如何,感谢建议,我希望这个答案也帮助别人。


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

For example,

C:\> C:\my-perl-scripts\foo.pl bar

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

C:\> perl C:\my-perl-scripts\foo.pl bar

works as expected.

Is this a configuration issue?

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.

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

Any ideas or recommendations?

Edit: 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:\Perl\bin\perl.exe" "%1" %*

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

C:\>t a b

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

C:\>t.pl a b

C:\>

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.

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.

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

解决方案

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_ROOT\Applications\perl.exe\shell\open\command

It should have a (Default) string value of "C:\Perl\bin\perl.exe" "%1" %*

When I found this entry, it was set to "C:\Perl\bin\perl.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天全站免登陆