Where does pp (PAR) unpack add (-a) files?

后端 未结 3 498
遇见更好的自我
遇见更好的自我 2020-12-11 19:19

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 l

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 19:55

    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.

    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;
    

提交回复
热议问题