Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
777 views
in Technique[技术] by (71.8m points)

windows - How do I run programs with Strawberry Perl?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>in, but others may end up in the site specific directory <installdir>sitein. The command

dir C:strawberryack* /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_MACHINESOFTWAREClasses.plShellOpenCommand (or HKEY_CURRENT_USER if it's for the current user only) and set the (Default) value to

"C:strawberryperlinperl.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...