1

I am pretty new to PAR::Packer and I have written a script in Perl.

The problem I am having is when I compile it to .exe and include two files (so it's portable) the EXE file errors out with "cannot open file, no such file or directory"

I can easily make the script into an .exe file and use it as long as the C:\temp directory is there. But I want it to use the files that were included in the .exe and not the C:\temp directory.

Here is the part of the script in question:

open($patch1, '<', "C:/temp/patch1.bin") or die "cannot open this file: $!";
binmode($patch1);
open($patch2, '<', "C:/temp/patch2.bin") or die "cannot open this file: $!";
binmode($patch2);

And like I say, all I want it to do is use the files that were included into the .exe and not the files from the C:/temp directory.

I reckon it could be how I've coded it, but I've tried "./patch1.bin" instead of "C:/temp/patch1.bin"

How can I fix this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
james28909
  • 554
  • 2
  • 9
  • 20
  • also i should add all this script does, is open a file, seek to certain offsets, then it writes $patch1 and then seeks to a different offset and writes $patch2. its just a simple seek and write script. – james28909 Nov 28 '13 at 19:33
  • 1
    Anyway, short answer: see http://search.cpan.org/perldoc?PAR::Tutorial#Accessing_packed_files – Ilmari Karonen Nov 28 '13 at 20:12
  • im apologize if i have duplicated a question. but this is a very very basic script and perl2exe will compile and include the files and it will execute the script and use the files from within the exe. i am trying to accomplish the exact same thing so i can make this portable for any windows pc. but the problem is i do not want to use perl2exe as the .exe's made with it have a 2 sec delay upon exiting the cmd window. i am trying to do away with this 2 sec delay pretty much. – james28909 Nov 28 '13 at 22:01
  • also, any help explaining this would be very useful. i am not an expirenced programmer by any means and any clarification is greatly appreciated – james28909 Nov 28 '13 at 22:11
  • Please include a complete script that exhibits your problem (trimmed down to the bare minimum to reproduce the problem). – Jonathan Hall Dec 05 '13 at 18:17

1 Answers1

1

The code in your question tries to open two files, named patch1.bin and patch2.bin, from the directory C:/temp. If those files are not present in that directory, the open will fail.

In the comments, you claim that perl2exe will somehow make those files appear in that particular directory if they've been bundled with our program. I rather doubt that. According to the perl2exe user manual, bundled files will be extracted into a directory whose name is given by:

$temp_dir = ( $ENV{TEMP} || $ENV{TMP} || $ENV{WINDIR} || '/tmp' ) . "/p2xtmp-$$";

Depending on your OS and settings, this might be a subdirectory of C:/temp, but it cannot be the directory C:/temp itself (since it must always contain p2xtmp somewhere in the path). Indeed, if perl2exe did extract its bundled files directly into C:/temp, or into any other fixed directory, that would be a recipe for disaster if two programs compiled using perl2exe were ever running at the same time and had bundled files with the same name.

Anyway, as the page I linked to suggests, the recommended way to access bundled files under PAR is using PAR::read_file(). For example, if you had a file name patch1.bin included in your PAR bundle using pp -a, you could read its contents using:

my $contents = PAR::read_file('patch1.bin');

If you need more advanced access to bundled files, you can obtain an Archive::Zip object pointing to the entire PAR file using:

my $zip = PAR::par_handle($0);

and then use that to access the archive members directly.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
  • thanks, and you are right. now that i remember... i had made an installer for this tool and it was portable. it would build the directory "c:\temp" and would add the patch files there. that is what i did last time to get around this same problem. i will have to try to understand this more lol. thank you very much for the help :) – james28909 Nov 29 '13 at 01:50