Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 885
vlee Avatar asked Jan 14 '09 19:01

vlee


People also ask

What is Assoc CMD?

Displays or modifies file name extension associations. If used without parameters, assoc displays a list of all the current file name extension associations. Note. This command is only supported within cmd.exe and is not available from PowerShell.

How do I pass a command line argument in Windows?

For example, entering C:\abc.exe /W /F on a command line would run a program called abc.exe and pass two command line arguments to it: /W and /F. The abc.exe program would see those arguments and handle them internally.

How do you supply command line arguments in Visual Studio?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.


2 Answers

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
like image 172
VonC Avatar answered Nov 15 '22 04:11

VonC


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.

like image 30
devio Avatar answered Nov 15 '22 04:11

devio