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

时间:2022-04-29 23:15:26

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

如何在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):

我最近建立了一台运行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

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

运行“foo.pl 1 2 3”不合意地产生:

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

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

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

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.

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

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

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

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

任何帮助,将不胜感激。这让我很沮丧。

4 个解决方案

#1


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

我刚刚在我的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

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

这意味着devio是对的:它必须是一个“文件关联”问题;

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

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

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

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


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
  • 在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)
  • 似乎Vista上的常规扩展管理器没有传递参数(意思是“C:\\ Perl64 \\ bin \\ perl.exe \”\“%1 \”没有%*参数)

  • the registry addition is necessary as documented by the SO
  • 如SO所记录的那样,注册表的添加是必要的

#2


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

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

HKEY_CLASSES_ROOT\.pl 

contains default string "Perl"

包含默认字符串“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.

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

#3


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

Vista的文件扩展管理器删除了将参数传递给程序的功能。您必须手动编辑注册表,如devio提及(或使用其他程序编辑文件扩展名)。

#4


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

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

#1


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

我刚刚在我的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

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

这意味着devio是对的:它必须是一个“文件关联”问题;

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

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

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

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


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
  • 在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)
  • 似乎Vista上的常规扩展管理器没有传递参数(意思是“C:\\ Perl64 \\ bin \\ perl.exe \”\“%1 \”没有%*参数)

  • the registry addition is necessary as documented by the SO
  • 如SO所记录的那样,注册表的添加是必要的

#2


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

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

HKEY_CLASSES_ROOT\.pl 

contains default string "Perl"

包含默认字符串“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.

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

#3


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

Vista的文件扩展管理器删除了将参数传递给程序的功能。您必须手动编辑注册表,如devio提及(或使用其他程序编辑文件扩展名)。

#4


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

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