I want my Perl scripts to behave just like any other executable (*.exe file).
myscript.pl
I want it to execute instead of opening in a text editor.myscript.pl
instead of perl myscript.pl
.myscript
instead of myscript.pl
.program | myscript
instead of program | perl myscript.pl
.There are a number of changes you have to make on Windows to make all of these things work. Users typically stumble upon things that don't work one at a time; leaving them confused whether they've made an error, there's a bug in Perl, there's a bug in Windows, or the behavior they want just isn't possible. This question is intended to provide a single point of reference for making everything work up front; ideally before these problems even occur.
Related questions:
Perl does not come pre-installed with Windows. To work with Perl programs on Windows, Perl will need to be manually downloaded and installed. ActiveState offers a complete, ready-to-install version of Perl for Windows. Click on the appropriate download link.
Note: The actions below require administrative privileges. For steps utilizing the command prompt it must be launched via "Run as administrator" on Windows Vista / Windows 7.
Run the following commands at a shell prompt:
assoc .pl=PerlScript ftype PerlScript=C:\bin\perl.exe "%1" %*
Replace C:\Perl\bin\perl.exe
with the path to your Perl installation. This enables you to run myscript.pl
instead of perl myscript.pl
.
Default install locations are:
C:\Perl
C:\Strawberry
.PL
to your PATHEXT environment variable.This makes Windows consider *.pl files to be executable when searching your PATH. It enables you to run myscript
instead of myscript.pl
.
You can set it for the current cmd session
set PATHEXT=%PATHEXT%;.PL
To set it permanently (under Windows Vista or Windows 7)
setx PATHEXT %PATHEXT%;.PL
Under Windows XP you have to use the GUI:
;.PL
to the current value.I/O redirection (e.g. program | myscript
) doesn't work for programs started via a file association. There is a registry patch to correct the problem.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
InheritConsoleHandles
REG_DWORD
Decimal
1
Warning: In principle, this should only be necessary on Windows XP. In my experience it's also necessary in Windows 7. In Windows 10 this is actively harmful—programs execute but produce nothing on stdout/stderr. The registry key needs to be set to 0 instead of 1.
See also:
If patching the registry isn't an option running program | perl -S myscript.pl
is a less annoying work-around for scripts in your PATH.
Adding a drop handler for Perl allows you to run a Perl script via drag & drop; e.g. dragging a file over the file icon in Windows Explorer and dropping it there. Run the following script to add the necessary entries to the registry:
use Win32::TieRegistry; $Registry->Delimiter("/"); $perlKey = $Registry-> {"HKEY_CLASSES_ROOT/Perl/"}; $perlKey-> {"shellex/"} = { "DropHandler/" => { "/" => "{86C86720-42A0-1069-A2E8-08002B30309D}" }};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With