passing argument not working...


Romuald Favre

Hi there,

I just installed Perl (v. 5.6.1. built for MSWin32 from ActiveState)
on a new server Windows 2000.
Amazingly the passing of arguments doesn't work !

I saved the following code in a file saved in "" :

#!/bin/perl -s

print STDOUT "NbArguments: $#ARGV\n";
print STDOUT "$ARGV[0], $ARGV[1]\n";

When I call it by " arg1 arg2", I get:
NbArguments : -1

I ran the same code on 2 other machines (XP and W2000): it works
I also installed another Perl version (INDIGOPERL) on this Server
W2000... and I keep getting the same weird behaviour !
Any idea ??? Does it have to do with the configuration or with
registry entries ?

Thanks for your contribution !


Romuald Favre

The problem has been solved in the meantime...

Surprisingly on this W2000 machine, I need to launch a perl script in
beginning with the command "perl" in order to have the arguments
recognized and passed further:
"perl arg1 arg2" and not just " arg1 arg2"
On the other W2000 machine that I have, it isn't necessary to begin
with the "perl" command... Strange, but it works that way!
Have a great day
Mar 12, 2007
Reaction score
Getting Perl arguments to work in Windows

I believe the following is the answer to why it works on one machine and not the other...

When you setup the file associations for the .pl (or whatever) extension... click on the Advanced button, then Edit the "Open" action. In here you'll see the "Application used to perform this action" field..
When this is first created... it looks like this..

"C:\indigoperl\perl\bin\perl.exe" "%1"

This tells it to pass only the "" filename into the perl.exe executable..
If you add more variables to this line... such as:

"C:\indigoperl\perl\bin\perl.exe" "%1" "%2" "%3" "%4" "%5" "%6" "%7" "%8" "%9" "%10"

then windows will forward each of these as well to the perl executable.
For the example above this will ONLY forward 9 command-line entries to your script. Thus, if you need more, then add more.

Now, when you type the following one two three four

it get's forwarded into perl.exe as

perl.exe one two three four

and the ARGV works fine at that point.
Jul 9, 2008
Reaction score
Re: Getting Perl arguments to work in Windows

This is all very interesting.

I too am using Windows 2000, and I noticed that sometimes my Perl script can see the command line arguments and sometimes not.

I have a script which lists its command-line arguments (parameters).
I am running Indigo Perl.

It behaves correctly if I type at the command prompt
perl a b c
but it doesn't see them if I just type a b c
or even
listargs a b c

Either of the latter two find and execute the script because .PL is among the extensions listed in my PATHEXT environment variable, but neither sees the parameters "a b c".

I tried the fix amcq suggested, but when I go to Control Panel / Folder Options / File Types, extension .PL is not listed there. I tried adding it, but it was gone the next time I opened this dialog. So I'm mystified about how Windows knows this is a Perl file...

Any suggestions are welcome.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads