How do I run programs with Strawberry Perl?
Asked Answered
T

4

28

A coworker is trying to use ack (a Perl program) on his Windows machine, having tried it under Linux and decided he definitely wants to use it. He managed to get Strawberry Perl installed on his machine, but can't seem to figure out what to do to make ack run with it from a command prompt. He tried editing the #! line, but I knew that wouldn't work. I'm pretty sure Strawberry perl is in his PATH.

What do you need to do to run a general Perl program in your PATH on Windows using Strawberry?

Update: I'm seeing some information online about the PATHEXT variable, but not enough.

Twomey answered 20/3, 2009 at 18:54 Comment(2)
Withdrawing my answer since it's redundant and based on initially misunderstanding your question.Emblazon
I wish you'd left it, Frakkle. There was a useful piece of information in it for me, but I can't remember what it was!Twomey
D
22

First, be careful that the program is in the Path, not just perl.exe. The Perl binaries and core programs usually end up in <installdir>\bin, but others may end up in the site specific directory <installdir>\site\bin. The command

dir C:\strawberry\ack* /s

might aid your search. Make sure your Path reflects your setup.

There are two common ways, at least that I know of, to run a Perl program from the Windows Command Prompt.

The first is to create a batch version of the program with pl2bat, which will execute perl with the program. Installed programs usually do this automatically because MakeMaker and Module::Build take care of this.

The second is to create a .pl file association. This is done by creating the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.pl\Shell\Open\Command (or HKEY_CURRENT_USER if it's for the current user only) and set the (Default) value to

"C:\strawberry\perl\bin\perl.exe" "%1" %*

That way, you can call programs just by naming them with the .pl extension. Now you can invoke the program with program.pl.

You may have noticed that you can call a program on Windows without the extension. The program is searched for in the Path, but when there's no extension, PATHEXT is used to complete the name. Append .pl to the list, and you can invoke the program just with program. Note that the order in this list is important for the search, just as the order in Path matters.

Installers usually take care of the last two steps, but this knowledge is useful if you'd like to add your own or need to fix it.

Defray answered 21/3, 2009 at 16:25 Comment(0)
K
17

I haven't had a problem just installing ack and running it from the command line.

Is Strawberry Perl installed correctly? Can you run "perl" from cmd.exe?

C:\> perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
...

Did App::Ack installed correctly?

C:\> cpan App::Ack
...
Installing C:\strawberry\perl\site\lib\App\Ack.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Plugin.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Repository.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Resource.pm
Installing C:\strawberry\perl\site\lib\App\Ack\Plugin\Basic.pm
Installing C:\strawberry\perl\bin\ack
Installing C:\strawberry\perl\bin\ack.bat
Writing C:\strawberry\perl\site\lib\auto\ack\.packlist
Appending installation info to C:\strawberry\perl\lib/perllocal.pod
  PETDANCE/ack-1.88.tar.gz
  C:\strawberry\c\bin\dmake.EXE install UNINST=1 -- OK

If so, I don't see why you can't run "ack" from the command line:

C:\> ack --version
ack 1.88

Copyright 2005-2009 Andy Lester, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

If it isn't working, where in that chain are things broken? For example, if you can't run "perl" from the command line, then Strawberry didn't install correctly (or isn't in your PATH) and you'll need to fix that. But otherwise, ack gets installed with an "ack.bat" wrapper into the same path as "perl", so if you can run "perl" you should be able to run "ack".

Ketchup answered 20/3, 2009 at 20:3 Comment(3)
We didn't install App::Ack ... we installed the standalone ack script. I'll try install App::Ack through CPAN, and that'll probably work for this case, but I still want to know more generally how to make this work by modifying PATHEXT. :)Twomey
Yeah install App::Ack and then copy ack.bat from perl\site\bin into perl\bin (at least, that's what I had to do). No real need to modify PATHEXT.Emblazon
Thanks, xdg. That got it running for us.Twomey
D
3

Another solution is to create ack.exe with PAR::Packer - he would not need Strawberry at all.

Dysprosium answered 8/5, 2009 at 10:32 Comment(0)
V
0

1.Install strawberry-perl 2.Open perl Commandline 3.Write command perl test.pl

Steps

Vallee answered 17/5, 2019 at 4:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.