作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
这是我试图解决提出的无关问题的尝试 "Why don’t my system calls work in the Perl program I wrap with pp?"我在 linux 系统上创建了一个简单的 Perl 脚本:
new-net:~/scripts # cat ls_test.pl
@ls_out = `ls -l`;
map { print "$_\n" } @ls_out;
$out = `sh out_test.sh`;
print "$out\n";
此脚本调用一个简单的 shell 文件:
new-net:~/scripts # cat out_test.sh
echo "I'm here"
我使用 pp 将 Perl 脚本连同 shell 脚本打包到 ls_test 中:
new-net:~/test # unzip -l ls_testArchive: ls_test Length Date Time Name -------- ---- ---- ---- 0 07-13-09 16:41 script/ 436 07-13-09 16:41 MANIFEST 214 07-13-09 16:41 META.yml 93 07-13-09 16:41 script/ls_test.pl 538 07-13-09 16:41 script/main.pl 16 07-13-09 16:20 out_test.sh -------- ------- 1297 6 files
如果我在一个空目录中运行打包文件,则找不到 shell 脚本:
new-net:~/test # ./ls_testtotal 3391-rwxr-xr-x 1 root root 3466177 Jul 13 16:41 ls_testsh: out_test.sh: No such file or directory
如果我将 shell 脚本复制到目录中,打包的脚本会按预期运行:
new-net:~/test # ./ls_test
total 3395-rwxr-xr-x 1 root root 3466177 Jul 13 16:41 ls_test-rw-r--r-- 1 root root 16 Jul 13 16:20 out_test.shI'm here
那么,pp
打包脚本期望在哪里找到包含文件?以及应该如何在原始 Perl 脚本中配置对该包含文件的调用?
最佳答案
打包的可执行文件中的文件被提取到一个临时目录(通常是/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' } );
您还可以创建与您要运行的脚本同名的可执行文件的符号链接(symbolic link),然后运行它们。
实际上,重新阅读您的问题,简单地访问 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;
关于linux - pp (PAR) 在哪里解压添加 (-a) 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1125689/
我是一名优秀的程序员,十分优秀!