Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Include data in compiled perl .exe

by Anonymous Monk
on Mar 14, 2003 at 23:34 UTC ( #243206=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to read a executable file (or other data file) into a variable and compile the script with perl2exe or similar and have the executable-datas incorporated into the new executable file generated when compiling the perl-code ?


is it possible to call this exe-file in this variable, possible with command switches, and then afterwards go back to my perl executable?

I got this one executable file that I want, if possible, to use in a perl executable file but I only want one executable file alltogheter..

Replies are listed 'Best First'.
Re: Include data in compiled perl .exe
by dree (Monsignor) on Mar 15, 2003 at 02:47 UTC
    First of all you need to encode the exe:
    use strict; use warnings; use MIME::Base64 qw(encode_base64); my $buf; open(FILE, "$ARGV[0]") or die "$!"; binmode FILE; while (read(FILE, $buf, 60*57)) { print encode_base64($buf); } close FILE;
    so you can use it ( in this way:
    c:\>perl myexe.exe > mybase64.txt
    Now, you need the script ( that encapsulates and extracts this exe:
    use strict; use warnings; use Win32::API; use MIME::Base64 qw(decode_base64); my $exe_name="myexe.exe"; my $GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N') +; if(not defined $GetTempPath) { die "Can't import API GetTempPath: $!\n"; } my $lpBuffer = " " x 80; my $return = $GetTempPath->Call(80, $lpBuffer); my $TempPath = substr($lpBuffer, 0, $return); my $exe_full_path=$TempPath."\\".$exe_name; print $exe_full_path.$/; open (FILE , ">$exe_full_path") or die "$!"; binmode FILE; print FILE decode_base64($_) while (<DATA>); close FILE; system("$exe_full_path"); unlink $exe_full_path; __END__ TVqQAAMAAAQAAAAAAAAAAAAAA etc. (the content of mybase64.txt)
    this works for me on Windows XP and perl2exe 7:
    that produces an exe. If you run it you run the first exe incapsulated in.
    If you add a line like this:
    system("$exe_full_path -$ARGV[0]");
    you can run the first encapsulated exe with additional parmeteres passed by command line (of the first second exe).
      eh, think I forgot something: Thanks jand and special Thanks! dree for your code (it works).. Regards.
Re: Include data in compiled perl .exe
by jand (Friar) on Mar 15, 2003 at 00:03 UTC
    You can do this easily with PerlApp from the ActiveState Perl Dev Kit: Just use the --bind option to attach the file. There are various configuration options available, that let you autoextract this file to a TEMP directory that automatically gets added to the PATH etc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://243206]
Approved by dorko
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2021-04-20 15:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found