Problem passing arguments to scripts

Posted by bslipsk on 2007-01-11 11:42

I'm using the 5.8.8.819 build on XP and I'm having problems passing in arguments to my scripts. I have the binary directory in my path and the .pl extension associated with the compiler and in the PATHEXT environment variable (so I don't need to type 'perl' before or '.pl' after every script). However, when I use these, none of the arguments I pass in are recognized. For example:

P:\prophiat\bin>testParam 1 2 3 4 5
0

P:\prophiat\bin>perl testParam.pl 1 2 3 4 5
5
1
2
3
4
5

Any suggestions?

Thanks.

jeff.griffiths | Thu, 2007-01-11 17:41

When you call just the .pl file, it isn't set up to capture the arguments properly. Please do this from a command prompt:

C:\>ftype PerlScript=perl.exe %1 %*
C:\>assoc .pl=PerlScript

You should now be able to call scripts directly and have the args processed properly. the key here is called perl.exe with the ' %1 %*' appended - this tells perl to look for arguments...

--
JeffG | Komodo 4.0 Beta | MacBook Pro OS X Intel / Ubuntu 6.06 i386

bslipsk | Sun, 2007-01-21 09:24

I didn't have %* in my open call.

Thanks.

kiltme | Tue, 2007-02-06 15:40

This is a bug in the installer.

I had this happend on the last 3 machines I installed perl on.

The install.bat from the as distribution is NOT setting the file association correctly. (From ActivePerl-5.8.8.819-MSWin32-x86-267479.zip)

The msi package ActivePerl-5.8.8.820-MSWin32-x86-274739.msi will create the correct association.

tj_thompson | Thu, 2007-02-08 11:57

It appears I'm having a similar problem, but the above fix does not seem to solve it. Build is ActivePerl-5.8.8.820-MSWin32-x86-274739.msi. Here is some script output:

L:\tjthomps\bin>ds_cmt.pl -h
Can't open : No such file or directory

L:\tjthomps\bin>perl ds_cmt.pl -h
USAGE: ds_cmt.pl [-bkh]
-b : list both actual calculated sum of instances
and original footer value.
-k : keep total as listed in test time file
instead of actual instance sum calculated
by script.
-h : print usage/help message

The following is output from checking ftype and assoc commands:

L:\tjthomps\bin>ftype PerlScript
PerlScript=perl.exe %1 %*

L:\tjthomps\bin>assoc .pl
.pl=PerlScript

Can anyone provide some suggestions so I don't have to type "perl" in front of all my scripts? Thanks!

Thomas Thompson

jeff.griffiths | Thu, 2007-02-08 11:59

It just looks like you aren't processing @ARGV with this in mind? Try dumping it out for either situation and see what the difference is.

--
JeffG | Komodo IDE 4.0 | MacBook Pro OS X Intel / Ubuntu 6.10 i386

tj_thompson | Thu, 2007-02-08 12:39

Ok, modified the script to output @ARGV elements.

@ARGV in the first case (ds_cmt.pl -h) is empty. @ARGV in the second case(perl ds_cmt.pl -h) contains a single element "-h" as expected. This is before @ARGV is processed in any way in both cases.

It appears the -h is not being passed to the script correctly when using only the script name on the command line.

kiltme | Thu, 2007-02-08 13:42

Missing quotes?

What I have that works (from the msi package?):

c:\>assoc .pl
.pl=Perl

c:\>ftype Perl
Perl="C:\Perl\bin\perl.exe" "%1" %*

tj_thompson | Fri, 2007-02-09 11:40

Not sure exactly what the prolem was, but it appears to be fixed.

I went into the Tools->Folder Options menu and the File Types tab. Located the PL file extension, highlighted it, and clicked the change button. Associated it with the perl.exe file from here. All works as expected. Oddly, my ftype and assoc settings don't seem to have changed as a result of this:

L:\tjthomps\experiments_data\cnr_b2_pgm_comparison>ftype PerlScript
PerlScript=perl.exe %1 %*

L:\tjthomps\experiments_data\cnr_b2_pgm_comparison>ftype Perl
Perl="C:\Perl\bin\perl.exe" "%1" %*

L:\tjthomps\experiments_data\cnr_b2_pgm_comparison>assoc .pl
.pl=PerlScript

These appear to match what I had previously. *shrug* least it's working :) Thank you guys for the time you took to post and help out.

Walta | Wed, 2007-02-28 14:40

I was having the same problem and also tried all the above. Nothing worked. So I went to the windows explorer...

tools-options-fileTypes
select PL
select advanced
select Open
select edit
make sure your application used to peform action line looks like this
"C:\Perl\bin\perl.exe" "%1" %*

Even though I made the changes above via dos, this line was still wrong. It was still missing the %* .
Once I changed it , it started working.

hope this helps

joemcg | Thu, 2007-10-25 07:43

Ok, I have Vista Ultimate running as a host O/S and Vista Business running as a Guest OS with Virtual PC. I have the following test program:

#!/usr/bin/perl -w
use strict;

print "@ARGV\n";

I run the command:
test-arg.pl 1 2 3

It works on the Guest OS (Vista Business), but not on the Host OS (Vista Ultimate) BOTH were installed from exactly the same .msi file!

I look at associations and both systems print:

C:\perl-scripts\int\2>ftype perl
perl="C:\Perl\bin\perl.exe" "%1" %*

C:\perl-scripts\int\2>assoc .pl
.pl=Perl

What gives????

gftaylor | Tue, 2007-10-30 15:40

I had the same problem, but found a post which got me going again. I hope this helps you. It seems that a file association got set from an explorer window and left off the %* at the end. Changing it on the command line didn't override what was already set. To fix it, try running regedit and searching for perl.exe . If the line looks something like "C:\perl\bin\perl.exe" "%1", then change it to "C:\perl\bin\perl.exe" "%1" %*.

Good luck!

joemcg | Tue, 2007-10-30 17:11

You were correct about how the entry looked in the Registry, but I made the change you suggested and it had no effect.

david.p.schneider | Sat, 2007-11-17 18:12

After modifying the registry, it didn't work for me either. However, this string is in more than one place. I found and altered 2 and now it works on my Vista Home Premium.

Cheers!
Dave