ARGV doesn't work on Windows 2008?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #1

    ARGV doesn't work on Windows 2008?

    A script stopped working when I moved it from Win 2003 server to Win 2008. After some troubleshooting it seems that it was not grabbing the command line parameters.

    So I did a print $ARGV and exit at the beginning of the file and I get this:

    Code:
    Use of uninitialized value $ARGV at .... line X
    I'm using perl from a folder, not installed or in window's path.

    Thanks!


    Dan
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    $ARGV is a scalar variable. What you're wanting is @ARGV which is an array.

    I you want to post your script and how you're executing it, we should be able to find the problem.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Sorry, that's a PHP->Perl mistake.

      There isn't any script, just this:

      Code:
      print "Testing ARGV...\n"; 
      print @ARGV;
      print #$ARGV;
      It prints an empty line after that message of course.

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Syntax error, change:
        Code:
        print #$ARGV;
        to:
        Code:
        print $#ARGV;
        Or a better method to see what's in the array.
        Code:
        use Data::Dumper;
        print Dumper \@ARGV;

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          yes, that was a typo, I apologize. It remains the same though, still doesn't work.

          Whatever it takes to convince you :)

          here's my file now:

          Code:
          use Data::Dumper;
          print Dumper \@ARGV;
          Here's the output on Win 2k8:
          Code:
          C:\>test.pl test test test
          $VAR1 = [];
          Weird huh? Code works fine on my XP PC.

          Output On XP:
          Code:
          C:\tmp>test.pl test test test
          $VAR1 = [
                    'test',
                    'test',
                    'test'
                  ];
          I'm out of ideas. Googled with no avail.


          Dan

          Comment

          • RonB
            Recognized Expert Contributor
            • Jun 2009
            • 589

            #6
            Your file type association is not setup correctly.

            Run a test by executing your script like this:
            C:\>perl test.pl test test test

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              This is most puzzling because I have worked on both windows platforms you mentioned, doing Perl development of course, and never experienced this issue. I am anxious to see what happens with Ron's last suggestion.

              Comment

              • RonB
                Recognized Expert Contributor
                • Jun 2009
                • 589

                #8
                It's been my experience that this is a common problem when the OP has never installed perl and is using a port which makes you set these types of settings without a supplying any defaults.

                The action attribute of the open setting within the file type association should be set to something like this:
                "C:\Perl64\bin\ perl.exe" "%1" %*
                The key part being:
                "%1" %*
                which sets/allows for the acceptance of the script arguments aka @ARGV. Calling the perl interpreter directly and passing it the script and args will "get around" the problem, but is not the best/proper solution.

                Comment

                • numberwhun
                  Recognized Expert Moderator Specialist
                  • May 2007
                  • 3467

                  #9
                  Agreed! Lets see what happens when they run it.

                  Comment

                  • dlite922
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1586

                    #10
                    Ron was exactly right.

                    I half-heatedly explained that perl is not installed, but since it "worked" I didn't have any technical reasons why ARGV wouldn't work.

                    It does have to do with file association, because like he said when I gave my file to perl.exe it worked!

                    Code:
                    C:\temp\Perl64\bin>perl.exe C:\test.pl test test test
                    $VAR1 = [
                              'test',
                              'test',
                              'test'
                            ];
                    Awesome! Thank you.

                    Why not installed? This is a loaned/borrowed server and want to return it in the same exact shape I got it. (Running everything from inside a folder makes for easy cleanup later)

                    Thanks guys,


                    Dan

                    Comment

                    • numberwhun
                      Recognized Expert Moderator Specialist
                      • May 2007
                      • 3467

                      #11
                      I am certainly glad that Ron's suggestion was the issue. On another note, specifically the issue of returning the server in the condition you found it, portable apps are your friend. In fact, Strawberry Perl has a portable version that you can put on a stick. Enjoy!

                      Comment

                      Working...