rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

How to access text file added by -a option #18

Closed sincos2007 closed 5 years ago

sincos2007 commented 5 years ago

There is a text file named 11.txt has content:

1234567

under folder: ./data

I use command:

pp -o test -a ./data test1.pl

to pack folder data into result package test.

In test1.pl I write code:

exec “gedit ./data/11.txt”

When I run result package, an empty file named 11.txt is opened. How to access file I packed?

rschupp commented 5 years ago

Files added with -a or -A are added in the "root" of the zip that's part of the executable. You can view this by running

unzip -l my_pp_packed_executable

As such they are unpacked into the per-user, per-executable cache directory,$ENV{PAR_TEMP}. So you should use something like

exec “gedit $ENV{PAR_TEMP}/data/11.txt”;

Note that this cache area might not persist - it will be the same for every invocation of the identical executable and same user. However, it's usually located below /tmp, so might get cleaned up by periodic jobs (or on reboot, since /tmp is a tmpfs on most modern Linux systems). Note that running the executable does not chdir() into $ENV{PAR_TEMP}.

See the man page for pp if you want the files to appear in another directory below $ENV{PAR_TEMP}.

sincos2007 commented 5 years ago

I did a test, there should be an ‘inc’ between $ENV{PAR_TEMP} and data:

gedit $ENV{PAR_TEMP}/inc/data/11.txt

This works