5

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.

Kurt W. Leucht
  • 4,725
  • 8
  • 33
  • 45
vlee
  • 1,369
  • 3
  • 14
  • 23

4 Answers4

9

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I uninstalled and reinstalled ensuring association was selected (default) and I am an administrator. However, everything worked as expected once I imported it by copying and pasting your code block as pl.reg and executing it. Thanks! (now to see if this works for strawberry perl) – vlee Jan 14 '09 at 20:44
  • The extension manager is a specific program that comes up... I forget the exact name of it, but it only allows you to select a program, rather than giving you the option of modifying the command-line that calls the program like WinXP's extension editor. – Powerlord Jan 14 '09 at 21:43
  • @R. Bemrose: right, I understand your answer better now. I will try to check that tomorrow. – VonC Jan 14 '09 at 22:18
  • As a follow-up, I got argument-passing for strawberry perl to work and updated the http://win32.perl.org/wiki/index.php?title=Talk:Main_Page#Fun_with_File_Associations with the details. It definitely seems a bit hackish since I don't set assoc or ftype though. – vlee Jan 14 '09 at 22:34
8

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.

devio
  • 36,858
  • 7
  • 80
  • 143
  • I only see the following HKEY_CLASSES_ROOT\.pl\Perl\(default) = (value not set) HKEY_CLASSES_ROOT\.pl\Perl\ShellNew\(default) = (value not set) I discovered %* syntax in my win32.perl.org sleuthing. Vista uses the "assoc" and "ftype" functions which I already tried modifying to no avail :( – vlee Jan 14 '09 at 20:14
  • The actual command is in HKEY_CLASSES_ROOT\Perl\shell\Open\command, see my answer below – VonC Jan 14 '09 at 20:24
  • Since the command line find the perl interpreter when you start a .pl file, the association has to be *somewhere*. Search the registry for "perl.exe", and see whether you can apply this information – devio Jan 14 '09 at 20:35
2

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

Powerlord
  • 87,612
  • 17
  • 125
  • 175
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] ...

TheEye
  • 9,280
  • 2
  • 42
  • 58
  • 1
    All Perl variable names are case sensitive. Surely that's the case(!) in most programming languages? – Dave Cross Nov 17 '11 at 11:47
  • I guess I was just used to having argv and argc spelled with small letters (see java), so I didn't pay attention to the spelling in the examples ... – TheEye Nov 17 '11 at 12:18