passing argument not working...

Discussion in 'Perl' started by Romuald Favre, Aug 13, 2003.

  1. 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 "test.pl" :

    #!/bin/perl -s

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

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

    I ran the same code on 2 other machines (XP and W2000): it works
    normally...
    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 !

    R.Favre
    Romuald Favre, Aug 13, 2003
    #1
    1. Advertising

  2. 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 test.pl arg1 arg2" and not just "test.pl 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


    (Romuald Favre) wrote in message news:<>...
    > 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 "test.pl" :
    >
    > #!/bin/perl -s
    >
    > print STDOUT "NbArguments: $#ARGV\n";
    > print STDOUT "$ARGV[0], $ARGV[1]\n";
    >
    > When I call it by "test.pl arg1 arg2", I get:
    > NbArguments : -1
    > ,
    >
    > I ran the same code on 2 other machines (XP and W2000): it works
    > normally...
    > 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 !
    >
    > R.Favre
    Romuald Favre, Aug 14, 2003
    #2
    1. Advertising

  3. Romuald Favre

    amcq

    Joined:
    Mar 12, 2007
    Messages:
    1
    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 "example.pl" 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

    script.pl one two three four

    it get's forwarded into perl.exe as

    perl.exe script.pl one two three four

    and the ARGV works fine at that point.
    amcq, Mar 12, 2007
    #3
  4. Romuald Favre

    RichPasco

    Joined:
    Jul 9, 2008
    Messages:
    1
    Location:
    San Jose CA & Land O Lakes FL
    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 listargs.pl which lists its command-line arguments (parameters).
    I am running Indigo Perl.

    It behaves correctly if I type at the command prompt
    perl listargs.pl a b c
    but it doesn't see them if I just type
    listargs.pl 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.
    RichPasco, Jul 9, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    11
    Views:
    4,065
    =?Utf-8?B?aGFuIHpoaXlhbmc=?=
    Sep 22, 2005
  2. nutty
    Replies:
    4
    Views:
    392
    nutty
    Jun 11, 2006
  3. Trans
    Replies:
    3
    Views:
    192
    Robert Klemme
    Jan 26, 2005
  4. ±è ÁØ¿µ
    Replies:
    7
    Views:
    245
    Einar Magnús Boson
    Nov 27, 2008
  5. User1014
    Replies:
    1
    Views:
    182
    Richard Cornford
    Nov 30, 2006
Loading...

Share This Page