Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

pp -a is not working

by alw (Sexton)
on Aug 21, 2007 at 20:34 UTC ( #634186=perlquestion: print w/replies, xml ) Need Help??

alw has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to add an additional txt file to a PAR archive using the -a flag. The resulting .exe file works as long as it's not moved to another folder. If moved and executed the .txt file is not found. Here is a simple file
#!/usr/bin/perl open FH,"data.txt" or die " can't open file $!\n"; while ( <FH> ) { print $_; }
The data.txt file contains a few lines of anything. The command to generate the example.exe file is:
command prompt>pp -a "data.txt" -o example.exe
OS is windowsXP and perl version is 5.8.8 820 Activestate. I have tried different ways of entering the filename after the -a flag; -a "data.txt;/script/data.txt", etc but none seem to work. What am I doing wrong here? Thanks

Replies are listed 'Best First'.
Re: pp -a is not working
by Cody Pendant (Prior) on Aug 22, 2007 at 03:01 UTC
    An .exe created with pp creates a temporary directory (an invisible one) and writes files to it when it runs.

    So maybe changing the options about how and when it does that would help?

    The -C option is for "clean up" after it runs and does this for the first time (to improve speed), so perhaps it "knows" the files are supposed to be there the second time it runs, but if you've moved it they're missing.

    So try compiling it with -C and maybe it'll recreate that temp folder every time.

    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
Re: pp -a is not working
by Anonymous Monk on Aug 22, 2007 at 07:15 UTC
    You didn't follow tutorial
    Accessing packed files * To get the host archive from a packed program: my $zip = PAR::par_handle($0); # an Archive::Zip object my $content = $zip->contents('MANIFEST'); * Same thing, but with read_file(): my $content = PAR::read_file('MANIFEST'); * Loaded PAR files are stored in %PAR::LibCache: use PAR '/home/mylibs/*.par'; while (my ($filename, $zip) = each %PAR::LibCache) { print "[$filename - MANIFEST]\n"; print $zip->contents('MANIFEST'); }
      Your wrong I did read that tutorial and your right I completely ignored it. With these changes I can run the standalone .pl file or the .exe file in any location. Thanks
      #!/usr/bin/perl use strict; use Archive::Zip; use Archive::Zip::MemberRead; if ( open FH,"data.txt" ) { print "using normal data.txt file\n"; while ( <FH> ) { print $_; } } else { my $zip = PAR::par_handle($0); my $fh = new Archive::Zip::MemberRead($zip, "data.txt"); print "using packed data.txt file\n"; while ( defined( my $line = $fh->getline()) ) { print "$line\n"; } print "\nOr another way\n"; my $content = PAR::read_file('data.txt'); print $content; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://634186]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-04-20 20:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found