首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >pp(PAR)在哪里解包添加(-a)文件?

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

Stack Overflow用户
提问于 2019-03-20 00:12:35
回答 2查看 0关注 0票数 0

这是我试图解决无关的问题“为什么我的系统调用不能在我用pp包装的Perl程序中工作?” 我在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_test
存档:ls_test
  长度日期时间名称
 --------    ----   ----    ----
        0 07-13-09 16:41脚本/
      436 07-13-09 16:41清醒
      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个文件

如果我在其他空目录中运行压缩文件,则找不到shell脚本:

new-net:〜/ test#。/ ll_test
总计3391

-rwxr-xr-x 1 root root 3466177 Jul 13 16:41 ls_test

sh:out_test.sh:没有这样的文件或目录

如果我将shell脚本复制到目录中,则打包脚本将按预期运行:

new-net:〜/ test#。/ ll_test

总计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

那么,pp打包脚本在哪里可以找到包含的文件?如何在原始Perl脚本中配置对该包含文件的调用?

EN

回答 2

Stack Overflow用户

发布于 2019-03-20 08:17:13

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

Stack Overflow用户

发布于 2019-03-20 09:53:11

感谢大家为这个答案做出贡献。我正在添加这个答案,以提炼出每个人宝贵的输入部分,我曾经在我的特定应用程序中提出了适合我的解决方案。

该应用程序使用POE和Tk以ActiveState Perl编写,并使用pp打包分发。它使用了几个外部文件; 一些用于输入程序(来自DNS的数据),一些用于用户采取的操作(创建和删除DNS别名记录)。

PAR打包器(pp)包含使用-a参数的外部文件。这些文件将解压缩到包中创建的“临时”路径下的\ inc目录中,并可通过脚本使用

$ENV{PAR_TEMP}

解决方案的第一步是将此信息添加到POE“$ heap”。下面的行是在线状态“_start”;

$heap->{t_path} = "$ENV{PAR_TEMP}\\inc\\";

当我在Win32环境中工作时,我使用转义的反斜杠将\ inc目录附加到临时路径中。

当调用外部文件输入应用程序时,我使用变量(@zone)来返回数据;

@zone = `$heap->{t_path}dnscmd aus-dc1 /enumrecords company.pvt @`;

对于完成外部操作的调用,将调用文件而不保存输出;

`$heap->{t_path}cpau -dec -file $heap->{t_path}del_event.job -nowarn -wait`;

再次感谢大家的贡献,感谢stackoverflow提供这个优秀的环境。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100001008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档