The Task

On Windows, if you have a perl script and want to distribute it to others you need to ask users to install Perl runtime.

In most cases it would be great to avoid it by creating a single all-sufficient executable file.

Additionally it would hide a script code and would allow to embed all dependencies (libraries, text, database files and others) into one file.

You can download the sample from GitHub.

The most popular Perl Runtime is ActivePerl. Notice that you need to use 32-bit version of the runtime to be able to run final exe on any Windows.

The script we are going to pack is quite simple, it shows text from the external file hello.txt (this file be embedded as well):

use strict;
use warnings;
 
my $filename = 'hello.txt';
open(my $fh, $filename) or die "Could not open file '$filename' $!";
 
while (my $row = <$fh>)
{
    chomp $row;
    print "$row\n";
}
			

Prepare a package

First of all you need ActivePerl runtime, you can download it from the official website.

Important: runtime files bitness: 32-bit vs 64-bit.

Download 32-bit version of the runtime to be sure the output exe runs well on both 32-bit and 64-bit Windows.

Using 64-bit runtime files, a 64-bit executable will be produced. It doesn't run on 32-bit Windows.

At the same time if you use 32-bit runtime files, a 32-bit executable will be prepared that can run on both 32-bit and 64-bit Windows.

Download BoxedApp Packer, launch it.

To run a perl script you type:

> perl.exe hello.pl
Let's override command line for packed exe, to be able to run perl.exe with hello.pl without passing additional arguments. Click to "Override command line" and enter:
<BoxedAppVar:OldCmdLine> "<ExeDir>\hello.pl"
The packed exe will run as if hello.pl really passed.

The script is being executed by perl.exe (find it in <Perl installation directory>\bin) so add it as input file.

Then switch to Application Directory and add perl520.dll (again find it in <Perl installation directory>\bin), because perl.exe requires it.

As the script uses two modules: strict and warnings, also add strict.pm and warnings.pm (find them in <Perl installation directory>\lib).

And finally add the script file hello.pl and the text file hello.txt.

The important option you need to check to make the output exe properly is "Run packed exe in virtual environment". Check it.

Build it and run. It shows the text as expected!

Screenshots

1. Select perl.exe
Select perl.exe
2. Set output name
Set output name
3. Override command line
Override command line
4. Run in virtual environment
Run in virtual environment
5. Add files
Add files
6. Build and run. It works!
Packed perl script

Download

Both sources and BoxedApp Packer project are available on GitHub.