加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – pp(PAR)在哪里解包添加(-a)文件?

发布时间:2020-05-23 07:18:20 所属栏目:Linux 来源:互联网
导读:这是我试图解决引发的无关问题 “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

这是我试图解决引发的无关问题 “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 "$outn";

此脚本调用一个简单的shell文件:

new-net:~/scripts # cat out_test.sh
echo "I'm here"

我使用pp将Perl脚本和shell脚本一起打包到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脚本:

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脚本复制到目录中,则打包脚本将按预期运行:

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脚本中配置对该包含文件的调用?

解决方法

打包的可执行文件中的文件将解压缩到临时目录(通常为/ 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' } );

您还可以创建与您要运行的脚本同名的可执行文件的symolic链接,然后运行它们.

实际上,重新阅读您的问题,只需访问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;

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读