如何在 Vista 64 中通过文件关联传递命令行参数?

发布于 2024-07-11 15:51:37 字数 852 浏览 7 评论 0原文

如何在 Vista 64 中通过文件关联传递命令行参数?

我最近组装了一台运行 Vista Ultimate 64 位的 PC。 我注意到我传输的几个 Perl 脚本由于未传递命令行参数而失败。 作为一个简单的测试,我编写了以下内容 (foo.pl):

#!/usr/bin/perl -w
use strict;
my $num_args = $#ARGV + 1;
print "${num_args} arguments read\n";
print "$^X\n" # to see what was being used

运行“foo.pl 1 2 3”意外产生:

0 arguments read
C:\strawberry\perl\bin\perl.exe

运行“perl foo.pl 1 2 3”预期产生:

3 arguments read
C:\strawberry\perl\bin\perl.exe

在我的旧 Windows XP PC 上,两个调用都返回3 个参数。 我在这里记录了更多我的调查(win32.perl.org wiki talk),但我还没有找到有效的解决方案。

我也尝试过 ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi 无济于事。

任何帮助,将不胜感激。 这让我抓狂。

How can one pass command line arguments via file association in Vista 64?

I recently built a PC running Vista Ultimate 64-bit. I noticed several of the Perl scripts I transferred failed due to command-line arguments not being passed. As a simple test, I wrote the following (foo.pl):

#!/usr/bin/perl -w
use strict;
my $num_args = $#ARGV + 1;
print "${num_args} arguments read\n";
print "$^X\n" # to see what was being used

Running "foo.pl 1 2 3" undesirably yielded:

0 arguments read
C:\strawberry\perl\bin\perl.exe

Running "perl foo.pl 1 2 3" expectedly yielded:

3 arguments read
C:\strawberry\perl\bin\perl.exe

On my old Windows XP PC, both invocations returned 3 arguments. I documented more of my sleuthing here (win32.perl.org wiki talk), but I've yet to find a solution that works.

I've also tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi to no avail.

Any help would be appreciated. This is driving me batty.

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

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

发布评论

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

评论(4

平生欢 2024-07-18 15:51:37

我刚刚在 Vista 64 Ultimate 上尝试了 ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi,它成功了。

F:\prog\perl>foo.pl 1 2 3
3 arguments read
C:\Perl64\bin\perl.exe

这意味着 devio 是对:肯定是“文件关联”问题;

在资源管理器上,右键单击 .pl 文件并询问“打开方式”:使用“Perl 命令行解释器”,它将起作用(并选择“始终使用此程序打开此类文件”)。

对我来说,“Vista 的文件扩展管理器删除了向函数传递参数的能力”似乎是错误的...


我确实明白:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Perl\shell\Open\command]
@="\"C:\\Perl64\\bin\\perl.exe\" \"%1\" %*"

这意味着如果您的安装没有在注册表中放入这种值,那是因为:

  • 您没有选择在安装 ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi 期间关联,
  • 或者您的帐户没有足够的权限在注册表中写入任何内容。

注意:

  • Vista 上的常规扩展管理器似乎不传递参数(意思是 \"C:\\Perl64\\bin\\perl.exe\" \"%1\" 没有 %* 参数)
  • 需要添加注册表正如 SO 所记录的

I just tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi on my Vista 64 Ultimate and it worked.

F:\prog\perl>foo.pl 1 2 3
3 arguments read
C:\Perl64\bin\perl.exe

That means devio is right: it must be an "file association" issue;

On an explorer, right-click on your .pl file and ask "Open with": use the "Perl Command Line interpreter" and it will work (and select "always use this program to open this type of file").

To me, "Vista's file extension manager removed the ability to pass arguments to functions" seems wrong...


I do see:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Perl\shell\Open\command]
@="\"C:\\Perl64\\bin\\perl.exe\" \"%1\" %*"

Meaning if your installation did not put that kind of value in your registry, it is because:

  • you did not select the association during the setup of ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi
  • or your account has not enough privilege to write anything in the registry.

Note:

  • it seems the regular extension manager on Vista does not pass argument (meaning \"C:\\Perl64\\bin\\perl.exe\" \"%1\" without the %* argument)
  • the registry addition is necessary as documented by the SO
彻夜缠绵 2024-07-18 15:51:37

不知道 Vista 和 64 位,但在“经典”版本的 Windows 下,您可以编辑注册表:

HKEY_CLASSES_ROOT\.pl 

包含默认字符串 “Perl”

HKEY_CLASSES_ROOT\Perl\shell\open\command 

包含默认字符串:

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

其中 %* 是第一个之后的所有参数的宏。 可能 %* 丢失了。

Don't know about Vista and 64bits, but under "classic" versions of Windows you can edit the registry:

HKEY_CLASSES_ROOT\.pl 

contains default string "Perl"

HKEY_CLASSES_ROOT\Perl\shell\open\command 

contains the default string:

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

where %* is a macro for all parameters following the first. Probably the %* is missing.

清风无影 2024-07-18 15:51:37

Vista 的文件扩展管理器删除了向程序传递参数的功能。 您必须像 devio 提到的那样手动编辑注册表(或使用其他程序来编辑文件扩展名)。

Vista's file extension manager removed the ability to pass arguments to programs. You have to manually edit the registry like devio mentions (or use another program to edit file extensions).

画骨成沙 2024-07-18 15:51:37

对于 Perl 初学者来说,还有趣的是 ARGV 区分大小写 ...只需花一个小时尝试找出为什么我的命令行参数没有传递,而只是我使用了 argv [0] 而不是 ARGV[0] ...

Also interesting to know for a Perl beginner is that ARGV is case-sensitive ... just spend an hour trying to find out why my command line parameters are not passed, and it was just that I used argv[0] instead of ARGV[0] ...

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