Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Strange problem with Windows 7 command line and perl

by anonypl (Novice)
on Feb 12, 2017 at 14:46 UTC ( [id://1181812]=perlquestion: print w/replies, xml ) Need Help??

anonypl has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm observing a very strange problem with perl. I downloaded and installed Strawberry Perl 5.24.1 from the Strawberry Perl site and installed it. As shown in the snippet of the path variable below, relevant strawberry perl paths seem to be added.

C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin

When I run the  perl --version or  perl -V commands, I get this

C:\Users\pmu>perl --version 'perl' is not recognized as an internal or external command, operable program or batch file. C:\Users\pmu>perl -V 'perl' is not recognized as an internal or external command, operable program or batch file.

But, I can execute a perl script if I type the name by itself, but not if I prepend it with the perl command like so:

C:\Users\pmu>more first.pl use warnings; use strict; use diagnostics; my @arr = ('a'..'z'); for my $stuff (@arr) { print "$stuff "; } C:\Users\pmu>first.pl a b c d e f g h i j k l m n o p q r s t u v w x y z C:\Users\pmu>perl first.pl 'perl' is not recognized as an internal or external command, operable program or batch file. C:\Users\pmu>

I have no idea why this is happening. Any help would be appreciated.

Replies are listed 'Best First'.
Re: Strange problem with Windows 7 command line and perl
by haukex (Archbishop) on Feb 12, 2017 at 15:13 UTC

    Hi anonypl,

    It's been a while since I had to deal with this kind of problem on Windows, but if memory serves, changes to PATH don't go into effect immediately. So did you already try rebooting? And, if so, what does echo %PATH% (from the same command window in which perl doesn't work) show you?

    Regards,
    -- Hauke D

      "So did you already try rebooting?"

      A reboot isn't required, starting a new instance of the command prompt will work fine.

Re: Strange problem with Windows 7 command line and perl
by poj (Abbot) on Feb 12, 2017 at 15:06 UTC

    What do you get using the full path

    c:\Users>c:\strawberry\perl\bin\perl -v

    poj

Re: Strange problem with Windows 7 command line and perl
by FreeBeerReekingMonk (Deacon) on Feb 12, 2017 at 16:07 UTC
    You have a 32 bit build, so the information I gave you is wrong.

    Try:

    1. Run the CMD as Administrator. Maybe it is a permission problem.

    old message (wrong information):

    I have 5.24.0 and the bug is not there. (work-machine, sorry not able to install your version to check your bug)

    However, when you run a script, it is not run through the PATH but through file association (run extension XYZ with this exe).

    So my guess is that you have a 64 bit Perl, but running on a 32 bit CMD prompt

    (There is both a 32bit and 64bit version of the command processor (cmd.exe))

    The 32 bit version is: C:\Windows\sysWOW64\cmd.exe

Re: Strange problem with Windows 7 command line and perl
by anonypl (Novice) on Feb 12, 2017 at 17:56 UTC

    Hi

    I did start a new instance of command line still the problem persisted. After that, I rebooted and tried again, but the problem was still there. As stated earlier, I dropped to PowerShell and it worked. But the moment I get out of PowerShell, it stops working.

    C:\Users\pmu>perl 'perl' is not recognized as an internal or external command, operable program or batch file. C:\Users\pmu>powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\Users\pmu> perl --version This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x +86-multi-thread-64int Copyright 1987-2017, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. PS C:\Users\pmu> exit C:\Users\pmu>perl 'perl' is not recognized as an internal or external command, operable program or batch file. C:\Users\pmu>

    This is something that I truly do not understand. Things are pretty straightforward in linux. I just have to edit the $PATH variable and things generally work consistently.

      Using the "Name" give by your association:
      >assoc .pl .pl=Perl_program_file
      Check your registry by running :
      >reg query "HKEY_CLASSES_ROOT\Perl_program_file\shell\Execute Perl Pro +gram\command"
      Mine shows:
      HKEY_CLASSES_ROOT\Perl_program_file\shell\Execute Perl Program\command (Default) REG_SZ C:\Strawberry\perl\bin\perl.exe "%1" %*
      This will locate the perl binary that ran your ".pl" script.

      After that, you need to make sure it is in the PATH.

              ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall

Re: Strange problem with Windows 7 command line and perl
by anonypl (Novice) on Feb 12, 2017 at 16:18 UTC

    Hi All,

    Interesting observation. I am able to execute the command if I drop to PowerShell

    PS C:\Users\pmu> perl --version This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x +86-multi-thread-64int Copyright 1987-2017, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. PS C:\Users\pmu>

      You need to start a new command line after any changes to these environment variables , hencyh why it work from your new powershell instance.

        Yep. Windows has an 'interesting' way of handling environment variables. One has to go pretty low-level with the Windows API to attempt to make it "Do The Right Thing", but it's just far easier to close the cmd window and open a new one. With that said, similar action can be seen on *nix as well in many cases...

        This isn't a Strawberry Perl issue. It'll happen with any software that changes ENV.

Re: Strange problem with Windows 7 command line and perl
by ww (Archbishop) on Feb 12, 2017 at 15:39 UTC

    Why does the first element in the path you show, 'C:\Strawberry\c\bin;," have a lower_case_c between "Strawberry" and "bin?"

      It contains gcc make and other Gnu tools to compile cpan modules that are not 'pure perl'.

      edit: d'oh... ninja'd

      Strawberry comes with GCC and it's in the C:\strawberry\c\bin directory by default. Windows is not case sensitive.

Re: Strange problem with Windows 7 command line and perl
by Anonymous Monk on Feb 12, 2017 at 15:10 UTC

    Hi,

    That works fine

    C:\Users\pmu>C:\Strawberry\perl\bin\perl --version This is perl 5, version 24, subversion 1 (v5.24.1) built for MSWin32-x +86-multi-thread-64int Copyright 1987-2017, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\Users\pmu>
Re: Strange problem with Windows 7 command line and perl
by anonypl (Novice) on Feb 12, 2017 at 16:13 UTC

    Hi all

    I tried rebooting but that doesn't help. I still have the same problem, though as Marto correctly stated, rebooting is not required. On a side note, thanks for your quick responses. You guys are all helpful.

      Ok, what about

      c:\Users>ftype perl

      and

      c:\Users>assoc .pl

      poj

        Hi,

        Just saw your message. Sorry missed it earlier. Here is what I get

        C:\Users\pmu>ftype perl File type 'perl' not found or no open command associated with it. C:\Users\pmu>assoc .pl .pl=Perl_program_file C:\Users\pmu>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1181812]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-03-29 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found