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

Hi all, I have a script that works as designed, but when I pack it into an .exe with PAR::Packer, it crashes at an open command. I'm on Windows, using ActivePerl.
I'm also at a complete loss. Am I doing something wrong? Did I stumble upon some weird incompatibility/bug? Is my PAR::Packer install broken?
Here's a shortened version of the script that exhibits the problem:
use strict; use warnings; use Tk; use utf8; my $mw = Tk::MainWindow->new; $mw -> Button(-text=>"Exit", -command => sub {exit(0)}) -> pack(-pady +=> 20); my $convert_bin; my $condition; if (!$condition) { my $bin_win = $mw->Toplevel(-title => 'A toplevel'); $bin_win->minsize(300, 200); $bin_win->update; $bin_win->raise; $bin_win->focus; $bin_win ->Label( -text => "Just testing", -font => 'bold',)->pack +(-pady => 10); $bin_win ->Label( -text => "Please click browse and specify a rand +om file.\nThe script will try and print the file path to c:/test/file +path.txt.",)->pack(-pady => 10); my $filepicker = sub { # this sub is launched when the Browse b +utton is pressed, see further down $convert_bin = $mw ->getOpenFile( -title => "Please choose the file", -multiple => 0, ); mkdir "c:/test"; open (OUT, ">:encoding(UTF-8)", "c:/test/filepath.txt") or pri +nt "Can't open file: $!"; # this fails when the script is packed i +nto an exe with PAR::Packer print OUT "File path: $convert_bin"; close OUT; $bin_win->destroy; }; # don't delete this ; my $buttbrowse = $bin_win -> Button(-text=>"Browse", -command =>[\&$fi +lepicker]) -> pack(-pady => 20); } MainLoop;

P.s. it creates a random folder on c:/, it was the first location that came to mind.

Replies are listed 'Best First'.
Re: Filehandle open fails in script packed with PAR::Packer
by Anonymous Monk on Jan 14, 2014 at 21:03 UTC

    it crashes at an open command.

    What does that mean exactly? Did eventviewer have something to say about it?

    What PAR command did you use to pack the script? Did you use "pp -x ..."?

    P.s. it creates a random folder on c:/, it was the first location that came to mind.

    Change your mind :)

    use File::Temp();
    my $tempfh = File::Temp->new;
    binmode $tempfh;
    print $tempfh ...;
    close $tempfh;

      Yes, I did use -x.
      I get a standard Windows error window stating that the .exe stopped working.
      Details according to Windows:
      Problem Event Name: APPCRASH Application Name: openfile_test.exe Application Version: 0.0.0.0 Application Timestamp: 4fba3b5e Fault Module Name: perl514.dll Fault Module Version: 5.14.2.1402 Fault Module Timestamp: 4e8f870c Exception Code: c0000005 Exception Offset: 000ad1bf OS Version: 6.1.7601.2.1.0.256.48 Locale ID: 1038 Additional Information 1: 0a9e Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 Additional Information 3: 0a9e Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Re: Filehandle open fails in script packed with PAR::Packer
by elef (Friar) on Jan 17, 2014 at 10:12 UTC
    I managed to install pp in a virtual machine. The same script is converted correctly there, so it must be something with my pp install. I have used pp it a lot before and it always worked correctly; perhaps some files got corrupted. I will try and update/reinstall all the relevant modules.

      Are you using the same version of Perl on the VM which works? Compare pp versions.