57

I have a .pl file and I want to execute that file in any system even though perl is not installed. How can I achieve it?

What would be some good examples to do that?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
User1611
  • 1,081
  • 4
  • 18
  • 27

8 Answers8

44

pp can create an executable that includes perl and your script (and any module dependencies), but it will be specific to your architecture, so you couldn't run it on both Windows and linux for instance.

From its doc:

To make a stand-alone executable, suitable for running on a machine that doesn't have perl installed:

   % pp -o packed.exe source.pl        # makes packed.exe
   # Now, deploy 'packed.exe' to target machine...
   $ packed.exe                        # run it

(% and $ there are command prompts on different machines).

ysth
  • 96,171
  • 6
  • 121
  • 214
  • hi can u explain me in brief... because am a newbie to perl.... whether i need to add this code in my perl source code or i have to execute it in command promt.... i have used modules like use Win32::OLE; use Win32::OLE::Enum; use Spreadsheet::BasicRead; how can i make my .pl to run in every systems.. Windows(prefereably) – User1611 Aug 06 '09 at 07:09
  • @lokesh, I think you'd have to package the script+modules with a precompiled perl interpreter **for each system** and put them in a zip file. – Inshallah Aug 06 '09 at 07:42
  • @Inshalla: for each different OS, not each different computer – ysth Aug 06 '09 at 07:57
  • 2
    @lokesh: first you install pp (part of the Par-Packer distribution, so you would install Par::Packer), then execute the pp command above, using your script in place of source.pl. It should detect what modules you use and include them. – ysth Aug 06 '09 at 08:00
  • @lokesh: I thought I did. What part do you need help with? – ysth Aug 06 '09 at 09:00
  • @lokesh There is a link to the documentation in ysth's post. Feel free to read them or ask ***specific*** questions. – Sinan Ünür Aug 06 '09 at 10:55
  • use PAR; % pp -o packed.exe try.pl # makes packed.exe $ packed.exe # run it hi this is my code and i have installed PAR but even though it throws "cant locate PAR.pm @INC..." can you tell me where i went wrong? can u tel me from the basic please.. i have never tried before.. i have a .pl file and then how can i use PAR to change into .exe can u tell me with an example – User1611 Aug 06 '09 at 11:55
  • @lokesh: How to install cpan distributions is really a different question. I suggest you create a new question, something like "I want to use the PAR::Packer pp utility. To install it, I did x, y, and z. When I try it I get this error output. How can I install it correctly?" – ysth Aug 06 '09 at 23:21
  • `pp` turned my 10 line perl script into an 8MB executable. Great. – CJ7 Aug 12 '16 at 04:13
  • @CJ7 it has to have the guts of perl, so it isn't going to be little, no – ysth Aug 12 '16 at 05:42
31
  1. Install PAR::Packer. Example for *nix:

    sudo cpan -i PAR::Packer

    For Strawberry Perl for Windows or for ActivePerl and MSVC installed:

    cpan -i PAR::Packer
  2. Pack it with pp. It will create an executable named "example" or "example.exe" on Windows.

    pp -o example example.pl

This would work only on the OS where it was built.

P.S. It is really hard to find a Unix clone without Perl. Did you mean Windows?

JPaget
  • 969
  • 10
  • 13
Alexandr Ciornii
  • 7,346
  • 1
  • 25
  • 29
  • 4
    PAR isn't a complete solution if the code you want to package needs to be cross-compiled. – brian d foy Aug 07 '09 at 03:08
  • 4
    Also, you don't need the -i switch to cpan. Just give it a list of modules and it figure that part out for you. :) – brian d foy Aug 07 '09 at 03:09
  • Yes `-i` is implied. MAN PAGE: `-i ... Install the specified modules. With no other switches, this switch is implied.` Another good rule of thumb in answers: Don't throw flags and parameters around in an answer w/o explaining what they do. – B. Shea Sep 20 '19 at 21:01
9

From perlfaq3's answer to How can I compile my Perl program into byte code or C?:


(contributed by brian d foy)

In general, you can't do this. There are some things that may work for your situation though. People usually ask this question because they want to distribute their works without giving away the source code, and most solutions trade disk space for convenience. You probably won't see much of a speed increase either, since most solutions simply bundle a Perl interpreter in the final product (but see How can I make my Perl program run faster?).

The Perl Archive Toolkit ( http://par.perl.org/ ) is Perl's analog to Java's JAR. It's freely available and on CPAN ( http://search.cpan.org/dist/PAR/ ).

There are also some commercial products that may work for you, although you have to buy a license for them.

The Perl Dev Kit ( http://www.activestate.com/Products/Perl_Dev_Kit/ ) from ActiveState can "Turn your Perl programs into ready-to-run executables for HP-UX, Linux, Solaris and Windows."

Perl2Exe ( http://www.indigostar.com/perl2exe.htm ) is a command line program for converting perl scripts to executable files. It targets both Windows and unix platforms.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
7

Look at PAR (Perl Archiving Toolkit).

PAR is a Cross-Platform Packaging and Deployment tool, dubbed as a cross between Java's JAR and Perl2EXE/PerlApp.

Jared Oberhaus
  • 14,547
  • 4
  • 56
  • 55
  • use PAR; % pp -o packed.exe try.pl # makes packed.exe $ packed.exe # run it hi this is my code and i have installed PAR but even though it throws "cant locate PAR.pm @INC..." can you tell me where i went wrong? can u tel me from the basic please.. i have never tried before.. i have a .pl file and then how can i use PAR to change into .exe can u tell me with an example – User1611 Aug 06 '09 at 11:53
6

And let's not forget ActiveState's PDK. It will allow you to compile UI, command line, Windows services and installers.

I highly recommend it, it has served me very well over the years, but it is around 300$ for a licence.

Mathieu Longtin
  • 15,922
  • 6
  • 30
  • 40
3

Cava Packager is great on the Windows ecosystem.

Rick
  • 591
  • 1
  • 9
  • 23
1

Perl files are scripts, not executable programs. Therefore, for them to 'run', they are going to need an interpreter.

So, you have two choices: 1) Have the interpreter on the machine that you wish to run the script, or 2) Have the script running on a networked (or Internet) machine that you remotely connect to (ie with a browser)

  • 3
    but, the two answers before you proved that your comment is invalid. – KevinDTimm Aug 06 '09 at 07:22
  • 2
    No, they didn't. PAR just archives a platform-specific perl binary in with the script you're distributing. – friedo Aug 06 '09 at 07:42
  • @kevindtimm: David Lewis is not wrong in what he says. The pp will simply package the perl interpreter along with the script. So it'd be equivalent to choice number 1. – Inshallah Aug 06 '09 at 07:44
  • use PAR; % pp -o packed.exe try.pl # makes packed.exe $ packed.exe # run it hi this is my code and i have installed PAR but even though it throws "cant locate PAR.pm @INC..." can you tell me where i went wrong? can u tel me from the basic please.. i have never tried before.. i have a .pl file and then how can i use PAR to change into .exe can u tell me with an example – User1611 Aug 06 '09 at 11:54
-1

On Mac OS X there may be perlcc. Type man perlcc. On my system (10.6.8) it's in /usr/bin. Your mileage may vary.

See perl-5.8.9 / perlcc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131