#ARGV is empty using ActivePerl in Windows 7 - perl

I have the following Perl script. I am trying to run it in Windows 7 using ActivePerl:
#!c:\Perl64\bin\perl.exe -w
use strict;
my $mp3splt_exe = 'c:\Program Files (x86)\mp3splt\mp3splt.exe';
my $mp3splt_args = '-o "#n #f" -g "r%[#o #N]" -f -t 6.0';
print #ARGV;
my $filename = $ARGV[0];
print "$mp3splt_exe $mp3splt_args $filename\n";
(as you can see, I am trying to create a wrapper for mp3splt :-) )
When I run it like this:
C:\Program Files (x86)\mp3splt>run_mp3splt.pl a
I get this:
Use of uninitialized value $filename in concatenation (.) or string at C:\Program Files (x86)\mp3splt\run_mp3splt.pl line 12.
c:\Program Files (x86)\mp3splt\mp3splt.exe -o "#n #f" -g "r%[#o #N]" -f -t 6.0
So, first of all, when I print #ARGV, nothing gets printed, and second of all, when I assign $filename = $ARGV[0], $filename is undef, so I get the warning.
So... what am I doing wrong? Why isn't the commandline parameter being passed to the script?

As others have pointed out perl blah.pl asdf works, while blah.pl asdf fails. This is because when you run the perl script directly, Windows realizes it must call perl, and uses the rule perl "%1", which only passes the script name to perl, not any of the parameters.
To fix this, you have to tell windows to use the rule perl "%1" %*
How to do that can be a little tedious:
Option 1
According to perlmonks, you should be able to use assoc and ftype on the commandline. In fact, if you type help ftype, it tells you how to setup perl:
assoc .pl=PerlScript
ftype PerlScript=perl.exe %1 %*
To run assoc requires cmd run as administrator on Window 7.
However, this didn't work for me. Windows ignored the association. I had to modify the registry. This may be due to the misguided advice to run the Default Programs utility on Win 7, which lets you specify the program to use for given file extensions. Unlike XP, this will not allow you to specify multiple command options (to be used in the right-click menu) -- it will only allow you to specify the program that is used when you double-click on a file (or run foo.pl from commandline).
Option 2
Modify the registry: HKEY_CLASSES_ROOT
If you've used the assoc/ftype commands, you may have entries for perl or PerlScript. As I said earlier, these will be ignored. Look for pl_auto_file, and drill down to the command:
HKCR\pl_auto_file\shell\open\command
Here the (Default) should be set to something like: "C:\Perl\bin\perl.exe" "%1"
Add the missing %* on the end of that and you should be good to go: "C:\Perl\bin\perl.exe" "%1" %*
No reboot necessary.
Option 3
If you're lazy and trusting, you can try using this as a reg file, and importing it into your registry:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\pl_auto_file\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
This should be sufficient to make blah.pl asdf work.

I've had the problem that if I executed on Win7:
perl myprog.pl a b c
the program got the parameters (in #ARGV) correctly, but if I executed:
myprog.pl a b c
the program would NOT receive the parameters.
I searched the web for a solution and soon found that it was no ActiveState perl problem but more likely a filetype association problem in Windows (Win7), (thanks to the PerlMonks website).
However all solutions changing the
assoc .pl=Perl
and the
ftype Perl="C:\Perl\bin\perl.exe" "%1" %*
did not solve the puzzle for me. I did notice that the assoc .pl was not used somehow because if I added assoc .plx=Perl and renamed my program to myprog.plx
myprog.plx a b c
worked perfectly !
So then I read this problem on the Microsoft forum were the Win7 "feature" Default Programs was mentioned, I found the solution to my problem:
Open Default Programs by clicking the Start button , and then click "Default Programs".
Select "Associate a file type or protocol with a program" and select ".pl" and click on "Change program". There was already a Perl Command Line Interpreter specified as Recommended Programs but instead I clicked on Browse and selected the Perl.exe myself. After closing the "Associate a file type ..." screen,
myprog.pl a b c
executed like a charm, all parameters were correctly retrieved by my program.
Hope that helps...

Perl ARGV problem solution in Windows 8.1:
HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command =
"C:\Perl\bin\perl.exe" "%1" %*
No re-boot needed.

I'm pretty sure Windows 7 doesn't understand the shebang line. What happens if you run this with perl run_mp3splt.pl a?

Related

How can I pass command line parameters to a Perl script? [duplicate]

I have the following Perl script. I am trying to run it in Windows 7 using ActivePerl:
#!c:\Perl64\bin\perl.exe -w
use strict;
my $mp3splt_exe = 'c:\Program Files (x86)\mp3splt\mp3splt.exe';
my $mp3splt_args = '-o "#n #f" -g "r%[#o #N]" -f -t 6.0';
print #ARGV;
my $filename = $ARGV[0];
print "$mp3splt_exe $mp3splt_args $filename\n";
(as you can see, I am trying to create a wrapper for mp3splt :-) )
When I run it like this:
C:\Program Files (x86)\mp3splt>run_mp3splt.pl a
I get this:
Use of uninitialized value $filename in concatenation (.) or string at C:\Program Files (x86)\mp3splt\run_mp3splt.pl line 12.
c:\Program Files (x86)\mp3splt\mp3splt.exe -o "#n #f" -g "r%[#o #N]" -f -t 6.0
So, first of all, when I print #ARGV, nothing gets printed, and second of all, when I assign $filename = $ARGV[0], $filename is undef, so I get the warning.
So... what am I doing wrong? Why isn't the commandline parameter being passed to the script?
As others have pointed out perl blah.pl asdf works, while blah.pl asdf fails. This is because when you run the perl script directly, Windows realizes it must call perl, and uses the rule perl "%1", which only passes the script name to perl, not any of the parameters.
To fix this, you have to tell windows to use the rule perl "%1" %*
How to do that can be a little tedious:
Option 1
According to perlmonks, you should be able to use assoc and ftype on the commandline. In fact, if you type help ftype, it tells you how to setup perl:
assoc .pl=PerlScript
ftype PerlScript=perl.exe %1 %*
To run assoc requires cmd run as administrator on Window 7.
However, this didn't work for me. Windows ignored the association. I had to modify the registry. This may be due to the misguided advice to run the Default Programs utility on Win 7, which lets you specify the program to use for given file extensions. Unlike XP, this will not allow you to specify multiple command options (to be used in the right-click menu) -- it will only allow you to specify the program that is used when you double-click on a file (or run foo.pl from commandline).
Option 2
Modify the registry: HKEY_CLASSES_ROOT
If you've used the assoc/ftype commands, you may have entries for perl or PerlScript. As I said earlier, these will be ignored. Look for pl_auto_file, and drill down to the command:
HKCR\pl_auto_file\shell\open\command
Here the (Default) should be set to something like: "C:\Perl\bin\perl.exe" "%1"
Add the missing %* on the end of that and you should be good to go: "C:\Perl\bin\perl.exe" "%1" %*
No reboot necessary.
Option 3
If you're lazy and trusting, you can try using this as a reg file, and importing it into your registry:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\pl_auto_file\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
This should be sufficient to make blah.pl asdf work.
I've had the problem that if I executed on Win7:
perl myprog.pl a b c
the program got the parameters (in #ARGV) correctly, but if I executed:
myprog.pl a b c
the program would NOT receive the parameters.
I searched the web for a solution and soon found that it was no ActiveState perl problem but more likely a filetype association problem in Windows (Win7), (thanks to the PerlMonks website).
However all solutions changing the
assoc .pl=Perl
and the
ftype Perl="C:\Perl\bin\perl.exe" "%1" %*
did not solve the puzzle for me. I did notice that the assoc .pl was not used somehow because if I added assoc .plx=Perl and renamed my program to myprog.plx
myprog.plx a b c
worked perfectly !
So then I read this problem on the Microsoft forum were the Win7 "feature" Default Programs was mentioned, I found the solution to my problem:
Open Default Programs by clicking the Start button , and then click "Default Programs".
Select "Associate a file type or protocol with a program" and select ".pl" and click on "Change program". There was already a Perl Command Line Interpreter specified as Recommended Programs but instead I clicked on Browse and selected the Perl.exe myself. After closing the "Associate a file type ..." screen,
myprog.pl a b c
executed like a charm, all parameters were correctly retrieved by my program.
Hope that helps...
Perl ARGV problem solution in Windows 8.1:
HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command =
"C:\Perl\bin\perl.exe" "%1" %*
No re-boot needed.
I'm pretty sure Windows 7 doesn't understand the shebang line. What happens if you run this with perl run_mp3splt.pl a?

Passing arguments to script, getting: "Use of uninitialized value $ARGV[0]"

Problem: Windows XP is not passing command line arguments to perl scripts.
Symptom: a simple command like:
say "Argument 1 (\$ARGV[0]) is: $ARGV[0], argument 2 (\$ARGV[1]) is: $ARGV[1].";
Resulted in:
Use of uninitialized value $ARGV[0] in concatenation (.) or string at...
Solution:
The root problem is in Windows XP. The default method for starting perl passes only the first variable, which is the script name. Result is that $ARGV[0] is uninitialized.
The fix is to edit the Windows registry at:
\HKEY_CLASSES_ROOT\Perl\shell\Open\command
And make the entry:
"C:\Perl\bin\perl.exe" %*
Result is:
C:\whatever>perl argtest.pl 1 2
Argument 1 ($ARGV[0]) is: 1, argument 2 ($ARGV[1]) is: 2.
Thanks especially to David W who pointed me in the right direction.
Note that #ARGV in Perl is not quite like argv in C.
C Perl
Name of the program argv[0] $0
1st argument argv[1] $ARGV[0]
2nd argument argv[2] $ARGV[1]
n-th argument argv[n] $ARGV[n-1]
So if you provide one command line arguments to a Perl script, it will be found in $ARGV[0]. $ARGV[1] will be uninitialized.
Download Cygwin and test your code in the Cygwin environment. I bet this is a Windows issue. (If you're a Unix head, you'll like Cygwin because it gives you the Unix/Linux like environment on your Windows machine. I don't use Windows without it.)
Windows uses suffixes to determine what program opens what files. Is your Perl script called argtest, argtest.bat or argtest.pl?
On Windows, make sure all of your Perl scripts use the *.pl suffix, so Windows will use whatever Perl parameter to execute them. Windows doesn't use the shebang.
Another possible issue: On Windows XP, I had a problem with Perl scripts with parameters because Windows had this as an execution string:
perl %1
which would execute the Perl program with my script, but ignore the parameters. I had to change this to:
perl %*
Unfortunately, Windows Vista through Windows 8 changed the way this is set. However, I have Windows 7 and don't have this issue. I did make sure to install Perl under C:\Perl and not C:\Program Files\Perl because of the space in the directory name. I also have Strawberry Perl installed.
There is a special Windows environment variable called PATHEXT. This allows you to type in foo instead of foo.pl. If Windows can't see how to execute your file, Windows goes through %PATHEXT and tries appending various suffixes until it finds one that works. You might want to append .PL to that environment variable, so you can type in foo instead of foo.pl all the time.
There are two ways that Windows knows it is supposed to use Perl to execute a program.
The command line begins with the perl executable and the name of the script to be run is provided as a command line argument. This is how it works on Unix and other environments, too.
Your system associates one or more extensions, such as .pl, .pm, and/or .cgi with the Perl application, and Windows will launch Perl when you type a filename with one of those extensions or click on a file with one of those extensions in the Windows explorer.
You have invoked your script simply as
argtest 1 2
and not one of
perl argtest 1 2
argtest.pl 1 2
That makes me think that Perl is not the first application that gets to look at the file referred to by argtest. Perhaps there is a file called argtest.bat or argtest.exe which has the task of getting Perl to run your Perl code. For some reason this intermediate program is not passing the command line arguments that you provide on to the Perl application.
Provide the code for this intermediate file and we can help some more.
UPDATE: David W proposes a 3rd way -- setting the PATHEXT environment variable to inclue .pl files and invoking argtest from the command-line -- see his answer.
Then if Window's file association with the .pl extension was messed up, say, set as just C:\Dwimperl\perl\bin\perl" and not "C:\Dwimperl\perl\binperl %*" then the OP would get the behavior that he describes.
In perl file name is not part of the array of arguments. At least in the test I did you must remove ARGV[2] or pass three arguments, like argtest 1 2 3

How to specify in a bat file that a script needs to be called in Cygwin mode?

I wrote a perl script which uses some linux commands (grep, ls etc..). I can successfully run this from Cygwin or Linux. I want this task to be run periodically on a Windows Server which has Cygwin installed. I was planning to use Windows task scheduler. But I am not sure how to specify in a Windows bat file, that my perl script needs to be called in Cygwin mode?
EDIT: I tried the command by Glenn. When I tried running the perl script, it doesn't seem to respond. So I tried with a sample script: test.sh, which has the following two lines:
ls -l
cd ..
Here is the screen capture of what I am getting:
I'm not a great fan of cygwin and personally prefer natively compiled versions of the GNU tools, e.g. GnuWin32.
I also wonder why you would be using grep, ls etc. from a Perl script. Most of that functionality can be handled natively by Perl and this usually results in much better portability and robustness.
Perhaps (untested): c:\cygwin\bash.exe -c /path/to/your/script.pl
UPDATE:
The last error message reveals one problem: your script is a DOS format file (CRLF line endings), while cygwin looks for UNIX format (LF line endings). The stray carriage returns at the end of each line is the problem. For example, there's no directory named "..\r"
Use a text editor where you can specify the line endings to use. In a bash shell, you can do dos2unix test.sh
The ls error indicates that /bin and /usr/bin are not in your bash environment's $PATH -- is that true?
Just add cygwin to your path before running perl. For example, I often run find in a dos shell, but get the rather horrible message FIND: Parameter format not correct. Bah! Instead I have to run find via a dos cmd file cyg.cmd:
c:> find . -iname interesting.txt
FIND: Parameter format not correct
c:> cyg find . -iname interesting.txt
sub/sub/interesting.TXT
c:> type bin\cyg.cmd
setlocal
PATH=c:\Progs\Cygwin\bin;%PATH%
%1 %2 %3 %4 %5 %6 %7 %8 %9
endlocal
The important bit here is the PATH=c:\Progs\Cygwin\bin;%PATH%.
BTW, I much prefer the cygwin versions of the tools rather than their MinGW equivalents—the environment is much closer to Mac/Linux, and portability is important after all.
You run cygwin bash, but you still have to setup your PATH. Unless you set it in your profile, but initialize the profile then with bash -i.
Either specify the full path to cygwin commands needed, like /bin/ls, /bin/grep,
or add c:\cygwin\bin and maybe other paths to your PATH beforehand.
2nd preferred. Like
schedule.bat:
PATH=C:\cygwin\bin;%PATH%
sh -c ./schedule.sh
schedule.sh:
#!/bin/sh
ls ...
grep ...
perl ...
schedule.sh gets the environment with the PATH from the parent process sh.exe, which inherits it from your bat.
Seperating shell scripts from batch files just for easier testing. You can call most cygwin programs from cmd.exe also.
You cannot set /usr/bin in your DOS PATH, DOS will not have a c:/usr directory. And it only works if you are in C:

How do I make Perl scripts recognize command-line parameters in the Win32 cmd console?

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.
Hmmm... sounds like the file association for *.pl is messed up somehow. I'm not on a Windows box, so I can't test this. You can check the file association stuff with either the ASSOC or FTYPE command on the command-line. IIRC, "ASSOC .pl" should tell you what the file type is and "FTYPE filetype command" tells the shell what to do with a Perl script. Try something like:
C:\> ASSOC .pl=perlscript
C:\> FTYPE perlscript=C:\Perl\bin\perl.exe %1 %*
From the looks of one of the command references that should do the trick. My guess is that the current association is not passing the parameters along to the script. You should be able to check that by using ASSOC .pl to figure out what the name of the file association is and then using FTYPE to print out the command that the shell is going to execute.
Update
I found an interesting thing that I want to note for posterity. I started seeing exactly this problem on a friends machine at work with respect to some Python scripts. ASSOC and FTYPE resulted in the expected output but the parameters were still not being passed along - exactly what was originally reported.
After a little digging, I found that the registry settings were created somewhere along the line as REG_SZ values. I deleted them and re-created them using ASSOC and FTYPE and everything started working... looking at the registry gave me the answer the new values were created as REG_EXPAND_SZ! These worked exactly as expected.
Update: Given that the following is correct, the only thing left to make sure is that command extensions are not turned off. Try:
cmd /e:on
on the command line before you run your tests. See also Windows XP cmd documentation:
Enabling and disabling command extensions
Command extensions are enabled by default in Windows XP. You can disable them for a particular process by using /e:off. You can enable or disable extensions for all cmd command-line options on a computer or user session by setting the following REG_DWORD values:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions\REG_DWORD
Set the REG_DWORD value to either 0x1 (that is, enabled) or 0x0 (that is, disabled) in the registry by using Regedit.exe. User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
E:\Temp> assoc .pl
.pl=Perl
E:\Temp> ftype Perl
Perl="C:\opt\Perl\bin\perl.exe" "%1" %*
E:\Temp> #echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PL;.PLX;.WPL;.py;.pyw
E:\Temp> cat t.pl
print "'$_'\n" for #ARGV;
E:\Temp> t a b c d e f g h j
'a'
'b'
'c'
'd'
'e'
'f'
'g'
'h'
'j'
I have used pretty much every ActiveState Perl distribution since 2004. These settings are enough to make it work.
To sum up.
ftype is old and cmd.exe doesn't care whatever it says.
The real deal is the HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command thing.
Just run: reg add HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command /ve /d "C:\strawberry\perl\bin\perl.exe \"%1\" %*" /f
and everything will be ok. (* given that "C:\strawberry\perl\bin\perl.exe" is the exact path to your perl installation.*)
/ve is meant to work on de “(Default)” REG_SZ value
/d is to assign “data” to the “value”
/f to force substitution (or overwriting) of the preexisting value
In fact, if assoc .pl=Whatever and ftype Whatever doesn't exist (never assigning a value to it, or doing ftype Whatever= to unassign), the scripts could still be invoked without prepending perl.exe.
So, if using Windows >= 6.0 (Vista, 2008, 7, etc.) just forget that the commands assoc and ftype exist at all. Don't bother. Go reg.exe!
I tried updating and associating .pl with the many different PERL entries in the registry that others have tried (.pl, Perl, PerlScript, pl_auto_file, Applications\perl.exe) and none of these worked. I'm running AS Perl 5.14.2 on Windows 7. I then noted that there was an entry for \Applications\perl5.14.2.exe in the registry and it was set to:
"C:\Perl\bin\perl5.14.2.exe" "%1"
Added the %* to this and then I was able to see data in #ARGV.
I also noted that on some of these entries I had a command path entry of "C"\Perl64\..." from a previous 64 bit PERL that I'd installed earlier and uninstalled when I found out that 64 bit PERL isn't as nice with IIS 7 as 32 bit PERL is. So there are dangling installation remnants that are probably affecting things too.
So the answer here is probably not a short one and is in simple words... "It depends..." (on your system and installation).
After fixing file association problem could not pass parameters. A user I support mistakenly associated .pl file extension with notepad after trying to run script from (Windows 7 Professional) command line for first time. Tried all the file association tricks and environment variable fixes to no avail. Uninstalled and reinstalled and tried 32 bit and 64 bit installations. Issue was only present on users profile.
Finally went into the registry and simply deleted the key from
HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command
and added back via
reg add HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command /ve /d "C:\strawberry\perl\bin\perl.exe \"%1\" %*" /f
started passing parameters again Thanks "lucretius"
I found this additional location in the registry that had to be updated before it would work for me. Note: The name after HKEY_USERS may be different on your machine.
Add %* to default string:
HKEY_USERS\S-1-5-21-1399284159-2775065347-350672949-4058_Classes\pl_auto_file\shell\open\command
"D:\Perl\bin\perl.exe" "%1" %*
Original author answer works. Here's a complete registry file for manually installing PERL on Windows, just add to PATH environment variable: ";C:\PERL\bin;" and make a perl.reg file with notepad containing this:
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\.pl]
[HKEY_CLASSES_ROOT\.pl]
#="Perl"
"PerceivedType"="text"
[HKEY_CLASSES_ROOT\.pl\Perl]
[HKEY_CLASSES_ROOT\.pl\Perl\ShellNew]
[HKEY_CLASSES_ROOT\.pl\PersistentHandler]
#="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT\Applications\perl.exe]
[HKEY_CLASSES_ROOT\Applications\perl.exe\shell]
[HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open]
[HKEY_CLASSES_ROOT\Applications\perl.exe\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\Perl]
[HKEY_CLASSES_ROOT\Perl\shell]
[HKEY_CLASSES_ROOT\Perl\shell\Open]
[HKEY_CLASSES_ROOT\Perl\shell\Open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[HKEY_CLASSES_ROOT\pl_auto_file]
#=""
[HKEY_CLASSES_ROOT\pl_auto_file\shell]
[HKEY_CLASSES_ROOT\pl_auto_file\shell\open]
[HKEY_CLASSES_ROOT\pl_auto_file\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe]
[HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe\shell]
[HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe\shell\open]
[HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pl]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pl]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pl\OpenWithList]
"a"="perl.exe"
"MRUList"="ab"
"b"="NOTEPAD.EXE"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pl\OpenWithProgids]
"pl_auto_file"=hex(0):
"Perl"=hex(0):
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Perl]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Perl\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Perl\shell\Open]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Perl\shell\Open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\pl_auto_file]
#=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\pl_auto_file\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\pl_auto_file\shell\open]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\pl_auto_file\shell\open\command]
#="\"C:\\Perl\\bin\\perl.exe\" \"%1\" %*"
[HKEY_LOCAL_MACHINE\SOFTWARE\Perl]
#="C:\\PERL\\"
"BinDir"="C:\\Perl\\bin\\perl.exe"
I installed Perl 5.24.3 on Windows2016 and found the JAMS scheduler Agent Shell ignored the .pl extension as if it did not exist. All good from DOS desktop.
The same config on Winows2008 worked fine.
The registry entries created by that ActiveState Perl Install, matched Lucretius Post above, but do not apply globally to all users. Not the default system user for example.
Logging in as the user the Shell will run as, and making the association helped.
Ideally there would be a registry twig to make .pl assoc global ?

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