Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Par::Packer and paths

by gri6507 (Deacon)
on Oct 27, 2011 at 18:04 UTC ( [id://934202]=perlquestion: print w/replies, xml ) Need Help??

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

I have used Par::packer (specifically, the pp utility) to create standalone executables in the past. This is the first time I need to reference other files. My question really is two fold:

  1. How to reference a file included with --addfile myfile.txt option? The partial answer is that any file which is included in the stand-alone executable is placed in $ENV{PAR_TEMP}/inc directory. So, when running the EXE, I can get at the included file using that path. However, how can I make access to that file universal from both EXE and when running the script through the Perl interpreter (perl foo.pl myfile.txt) ?
  2. My EXE has the following in it
    unless (my $return = do $script) { warn "could not parse $script: $@" if $@; warn "could not pull in $script: $!" unless defined $return; warn "could not execute $script" unless $return; }
    and $script is a user specified argument (a la $ARGV[0]). When I run this directly through the interpreter, my pwd is the directory where I am currently located, so that the relative path to $ARGV[0] is correct. However, when I run the pp'd EXE, the pwd is the PAR directory and the relative path to $ARGV[0] is no longer correct. How can I reconcile that?

As always, thanks in advance!

P.S. I know the risks of do(tainted_input), but because this tool is intended for internal distribution only, safety is not a concern.

Replies are listed 'Best First'.
Re: Par::Packer and paths
by Anonymous Monk on Oct 27, 2011 at 18:39 UTC

    How to reference a file included with --addfile myfile.txt option?

    Exactly as documented, PAR::read_file , example Re^4: introspection, or running pod2html on itself

    However, how can I make access to that file universal from both EXE and when running the script through the Perl interpreter (perl foo.pl myfile.txt) ?

    Through abstraction, naturally :)

    sub GimmeFile { if( $ENV{PAR} ){ PAR::read_file( shift ) } else { File::Slurp::read_file( shift ); } }

    ...pwd... How can I reconcile that?

    pp'ed programs do have the correct pwd, so what you're saying makes no sense

    Maybe you wish to not rely on pwd, but chdir to where you wish to be?

    or use GimmeFile above? Or maybe File::ShareDir::PAR?

      Thank you for the response. With regards to my first question, your solution is ideal. I did not know that that environment variable. Just a slight correction: the actual variable is $ENV{PAR_0}.

      I have to retract my second question. This was a user error. Near the top of my script I had a chdir($ENV{PAR_TEMP}) that I forgot about. That is why it appeared that my pwd was a PAR directory. Sorry about that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://934202]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found