Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Win7, ASSOCiation , and @ARGV

by ww (Bishop)
on Mar 14, 2012 at 02:26 UTC ( #959491=perlquestion: print w/ replies, xml ) Need Help??
ww has asked for the wisdom of the Perl Monks concerning the following question:

SOLVED! There's much useful info in this thread, which led to the conclusion that reinstalling Perl was the first best option. Using AS on Win7 (and probably elsewhere), right clicking the Perl executable in REMOVE PROGRAMS brings up 3 options, of which "Repair" uses the originally downloaded .msi.

... and, lo and behold, the quirks are gone!

I came across an interesting quirk recently (caveat: but it seems very likely that it's an OS issue, so don't invest a lot of attention unless you've an interest in something that appears to suggest a Perl issue -- and, that, and only at first glance).

Relying on Windows7's file ASSOCiation function to use Perl to execute the code below produces nothing but newlines when three arguments are provided on the command line, thus:

C:\>YA_ARGV_test.pl foo bar baz C:\>

That would appear to be a line for $ARGV[0], [1] and [2] and a fourth, blank as expected, before the prompt repeats.

But explicitly invoking Perl produces the expected result:

C:\>perl YA_ARGV_test.pl foo bar baz foo bar baz foo bar baz C:\>

The code in question is simplicity itself (well, almost -- except for the belt and suspenders mode):

#!/usr/bin/perl use 5.014; use feature qw(say); my @arr = @ARGV; say $ARGV[0]; say $ARGV[1]; say $ARGV[2]; for $_ (@arr) { say $_; }

Running a minimal version of the same code as a one-liner also produces the expected output:

C:\>perl -e "use 5.014; for $_ (@ARGV) { say $_; }" foo bar baz foo bar baz C:\>

...as does running the program in the debugger, invoked perl -d fn.pl arg arg arg./p>

That fact which refocuses my curiosity about whether the flaw lies with Win7's ASSOCiation or somewhere else.

The Perl and machine? AS v. 5.14.2; Win7, Home_Pro (correcting misstatement: Professional), 32 bit x86, SP1, and....

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

I mention those two checks -- with produce the 'book answers' -- because in a 2010 thread on a similar problem, ikegami noted the likelihood that OP's problems stemmed from a broken ASSOCiation. That doesn't appear to be the case, here.

Ideas? Ideas for testing hypotheses? Proven answers?

Comment on Win7, ASSOCiation , and @ARGV
Select or Download Code
Re: Win7, ASSOCiation , and @ARGV
by BrowserUk (Pope) on Mar 14, 2012 at 02:45 UTC

    I can't reproduce your finding on Vista:

    C:\test>perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +64-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2011, Larry Wall Binary build 1402 [295342] provided by ActiveState http://www.ActiveSt +ate.com Built Oct 7 2011 15:19:36 {snip} C:\test>assoc .pl .pl=Perl C:\test>ftype Perl Perl="C:\Perl64-14\bin\perl.exe" "%1" %* C:\test>type junk.pl #!/usr/bin/perl use 5.014; use feature qw(say); my @arr = @ARGV; say $ARGV[0]; say $ARGV[1]; say $ARGV[2]; for $_ (@arr) { say $_; } C:\test>junk 1 2 3 1 2 3 1 2 3

    Do you have cygwin installed?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      No re cygwin; haven't got to it yet on this new box.

      And thanks for the test on Vista. I think I'm going to have to revive boxen with XP and Win2k, and see how they fare.

Re: Win7, ASSOCiation , and @ARGV
by BillKSmith (Chaplain) on Mar 14, 2012 at 04:13 UTC
    Cannot duplicate results wilth perl 5.8.8 on XP. (Changed 'say' to 'print')
Re: Win7, ASSOCiation , and @ARGV
by Anonymous Monk on Mar 14, 2012 at 04:27 UTC
    ?? What do you get for
    echo %pathext%
    which -a perl
    perl -V
    set |grep -i perl
    doskey /macros:all |grep -i perl

    $ echo %pathext% .COM;.EXE;.BAT;.CMD;.PL $ which -a foo D:/junk/foo.COM D:/junk/foo.COM D:/junk/foo.EXE D:/junk/foo.EXE D:/junk/foo.BAT D:/junk/foo.BAT D:/junk/foo.PL D:/junk/foo.PL

    MACRO execute before COM before EXE before BAT before PL

    See also on win32 cmd.exe shell pipe | pl2bat, ftype/assoc

      Thank you! Your response made me check %pathext% where .pl is missing:
      C:>echo %pathext% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

      Of course, with no cygin (nor GNUtils) I have no grep or which but pursuing your other suggestions I ran across (BTW, en route, a suggestion to use setx PATHEXT=%PATHEXT%;.PL turned out to be invalid syntax - perhaps omitted from Win7, to judge by MS's documentationNote 1) a MS support page which referred me... which referred me... etc... eventually to what may be a fix but which requires a reboot... so:

      --more to come -- after the reboot :-(

      Updated, post reboot:

      Yech, way too much stumbling around in the dark. But START|COMPUTER|ADVANCED SYSTEM SETTINGS|(System Properties|ADVANCED (tab)|Environmental Variables| leads to a box where one can edit PATHEXT (to add the ".PL")

      Note 1 for earlier versions of Win, set ... was documented as valid ONLY for the session in which it was executed.

      See also Re: Out of date over <> and 5.10 et seq where ikegami, BrowserUK, tye and Corion discuss quirks, peculiarities, ASSOC decisions by MS and AS's implementation of its use.

      But recognize: adding .PL; .pl to %PATHEXT% was NOT a silver bullet; so I have more to seek/do, but this is already waaay too long, but one can hope others, similarly troubled may find some of this useful... so, some keys:

      '@ARGV failure' '<>' 'Association' 'PATH' 'PATHEXT'

        a suggestion to use setx PATHEXT=%PATHEXT%;.PL turned out to be invalid synta

        Type help set and read that manual :)

        While you're at it read help assoc and help ftype

Re: Win7, ASSOCiation , and @ARGV
by Not_a_Number (Parson) on Mar 14, 2012 at 09:45 UTC

    I can't reproduce your issue on my Windows 7:

    D:\progs\perl>YA_ARGV_test.pl foo bar baz foo bar baz foo bar baz C:\>assoc .pl .pl=Perl C:\>ftype perl perl="C:\Perl\bin\perl.exe" "%1" %*

    Same perl, same Windows config (except that it's Windows 7 Professional).

    Update: %PATHEXT% seems a red herring:

    C:\>echo %pathext% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.pyw;.RB;.RB +W

    Note the absence of .PL.

Re: Win7, ASSOCiation , and @ARGV
by cdarke (Prior) on Mar 14, 2012 at 16:24 UTC
    With the ftype you gave, on Windows 7, I cannot reproduce your problem. However, if I change the ftype to:
    perl="C:\Perl\bin\perl.exe" "%1"
    (omit the %*) then I can exactly reproduce your error. Check HKEY_CLASSES_ROOT\Perl\shell\Open\command in the registry?

      More puzzlement (perhaps because when we play in the registery, we're beyond my depth), how come:

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

      while regedit doesn't know that? Searching the registery, I find NOTHING for the exact string you posted (meaning, I assume, that I should perhaps set that?) but do find, searching for .pl:

      HKEY_CLASSES_ROOT | | | | | .pl (Default) REG_SZ ntpfile | | Content Type REG_SZ NoteTab Pro document | | Perceived Type REG_SZ text | | | Perl (Default) REG_SZ ntpfile | | | | | ShellNew (Default) REG_SZ (value not set) | | PersistentHandler (Default) REG_SZ {5e941....}

      ... the last of which says, "ww go out and RTFM (some more)!"

      Thank you.

        What do you get when you run this command?

        >reg query HKLM\Software\Classes\Perl\Shell\Open\Command HKEY_LOCAL_MACHINE\Software\Classes\Perl\Shell\Open\Command (Default) REG_EXPAND_SZ "C:\Perl64\bin\perl.exe" "%1" %*

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://959491]
Approved by BrowserUk
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-07-30 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls