打包的可执行文件中的文件被提取到一个临时目录(通常是/ tmp / par-USERNAME / cache- XXXXXXX)。要访问这些文件,请执行以下操作:
#!/usr/bin/perl
# Reads a data file from the archive (added with -a)
print PAR::read_file("data");
# Will execute "script2" in the archive and exit. Will not return to this script.
require PAR;
PAR->import( { file => $0, run => 'script2' } );
您还可以建立与可执行文件具有相同名称的可执行文件的符号链接,然后运行它们。
实际上,重读您的问题,仅访问PAR_TEMP环境变量可能更有用:
#!/usr/bin/perl
use File::Slurp qw(slurp);
$data_dir = "$ENV{PAR_TEMP}/inc";
$script_dir = "$data_dir/script";
print slurp("$data_dir/datafile");
# file access permissions are not preserved as far as I can tell,
# so you'll have to invoke the interpreter explicitly.
system 'perl', "$script_dir/script2", @args;