问题描述
这是我尝试解决所引起的无关紧要的问题为什么我的系统调用在用pp包装的Perl程序中不起作用? "我已经在linux系统上创建了一个简单的Perl脚本:
This is my attempt to cut through extraneous issues raised "Why don’t my system calls work in the Perl program I wrap with pp?" I have created a simple Perl script on a linux system:
new-net:~/scripts # cat ls_test.pl
@ls_out = `ls -l`;
map { print "$_\n" } @ls_out;
$out = `sh out_test.sh`;
print "$out\n";
此脚本调用一个简单的外壳文件:
This script calls a simple shell file:
new-net:~/scripts # cat out_test.sh
echo "I'm here"
我用pp将Perl脚本和Shell脚本打包到ls_test中:
I used pp to pack the Perl script along with the shell script into ls_test:
new-net:~/test # unzip -l ls_test
Archive: 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脚本:
If I run the packed file in an otherwise empty directory, the shell script is not found:
new-net:~/test # ./ls_test
total 3391
-rwxr-xr-x 1 root root 3466177 Jul 13 16:41 ls_test
sh: out_test.sh: No such file or directory
如果我将shell脚本复制到目录中,则打包的脚本将按预期运行:
If I copy the shell script into the directory, the packed script runs as expected:
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.sh
I'm here
那么,pp
打包脚本应该在哪里找到包含的文件?以及如何在原始Perl脚本中配置对该包含文件的调用?
So, where does a pp
packed script expect to find an included file? And how should a call to that included file be configured in the original Perl script?
推荐答案
打包的可执行文件中的文件被提取到一个临时目录(通常为/tmp/par-USERNAME/cache-XXXXXXX).要访问这些文件,请执行以下操作:
The files in a packaged executable are extracted to a temporary directory (usually /tmp/par-USERNAME/cache-XXXXXXX).To access these files do something like the following:
#!/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' } );
您还可以建立与可执行文件具有相同名称的可执行文件的符号链接,然后运行它们.
You can also make symolic links to the executable that have the same name as the script you want to run, and run those.
实际上,重读您的问题,仅访问PAR_TEMP环境变量可能更有用:
Actually, rereading your question, simply accessing the PAR_TEMP environment variable is probably more useful:
#!/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;
这篇关于pp(PAR)在哪里解压缩添加(-a)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!