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

Hi Monks,

I am new to Perl and going thru selected tutorials. At the moment I am trying to create an executable of my perlscript.

I am running Perl on Windows with Strawberry. Below is the version info.

This is perl 5, version 22, subversion 1 (v5.22.1) built for MSWin32-x64-multi-thread

I have installed the PAR:Packer module version 1.029

When I execute C:\>pp -o packed.exe hw.pl I get the error below.

Error removing C:/Users/DANIEL~1.LEG/AppData/Local/Temp/parl_MCNJgn.exe at C:/Strawberry/perl/lib/File/Temp.pm line 762, <DATA> line 1.

Nevertheless, the executable file is created and the script runs fine.

Does anyone know anything about this error? I could not find info about it. Since I am using a very simple script which is a combination of the tutorials I've been through I wonder if this error will do some real damage on complex scripts later on.

Please note that the path to parl_MCNJgn.exe in the error seems incorrect. The real path has my full name as supposed to DANIEL~1.LEG.

Cheers,

# Hello world program print "=======================================================\n"; use strict; use warnings; use Term::ReadLine; use feature qw(say); use Data::Dump; # -- Variable Definitions: can be done when variable is first used my $animal; my $banner; my $num; my $term; my $content; my $count; my +$email; my @animals; my @nums; my @mixed; my @sorted; my @backwards; my @fruit +s; my @colors; my @copyofFC; my %fruit_colors; my $ptime = 1; {# -- Scalars print "\n\n"; # \n must + be within "" so it interpolates the newline $animal = 'camel'; # '' and "" +are interchangeable if no special characters $banner = "hello world "; $num = 3; say $banner, $num + 1/2; say $animal; # Same as +print but ends with \n } {# -- Arrays print "\n\n"; @animals = ('camel ','llama ','owl ','dog ','shark ','ant '); @nums = (23,42,69); @mixed = ('camel',42,1.23,2.5); say $animals[0]; say $animals[1]; say $mixed[$#mixed] *2; # $#array i +s the last index in the array say @nums; # Print +all elements with no spaces in between say @animals; dd \@mixed; # Print + in array format i.e. ["camel", 42, 1.23, 2.5] Requires Data::Dump if (@animals < 10) { say $#animals+1; } # As Perl expects an sc +alar, @animals is the number of elements say @animals[0,1]; say @animals[2..$#animals]; @sorted = sort @animals; @backwards = reverse @nums; say @sorted; say @backwards; } {# -- Hashes print "\n\n"; %fruit_colors = ('apple ', 'red ', 'banana ', 'yellow ', 'kiwi ', 'gre +en ', 'coconut ', 'brown '); # Maps even indexed elements with follo +wing element e.g. apple => red say $fruit_colors{'kiwi '}; @fruits = keys %fruit_colors; # As hash +es have no particular internal order, retrieved keys don't either. @colors = values %fruit_colors; print @fruits, " => ", @colors, "\n\n"; @fruits = reverse sort @fruits; print @fruits, "\n", @fruit_colors{@fruits}, "\n"; } {# -- Conditional and looping constructs print "\n\n"; if (@fruits <5) {print "less than 5 | ";} unless (@fruits >5) {print "not greater than 5", "\n"} # "if no +t" statement print "One line if \n" if (1); print "One line unless \n" unless (0); $term = Term::ReadLine->new('Text'); $content = ''; $| = 1; # flushes p +rint as it is issued (i.e. do not wait for \n) print "\ntype input or press enter to exit"; while ( defined (my $con = $term->readline('input: '))){ last unless length $con; $content .= "$con "; # concatenate +string (i.e appends "$con " to the end of $content) } print "You entered: "; say $content; $| = 1; # Something + within previous while loop resets $| $count = 0; until($count == 5){ print 5-$count unless($count >5); print "Crashed: use Ctrl+C on Windows or Ctrl+D on Linux\n" if($co +unt >5) ; $count++; sleep($ptime); } for(my $i = 0; $i <= $count; $i++){ print $i; sleep($ptime); } print "\n"; print "$_ " foreach (@nums); # $_ points to val +ue in array foreach my $keyfruit (keys %fruit_colors){ print "\n$keyfruit\t$fruit_colors{$keyfruit}"; sleep($ptime); } } {# -- Files print "\n\n"; open(my $out, ">", "output.txt") or die "Can't open output.txt: $!"; + # ">" to write print $out %fruit_colors, "\n"; print $out "second line \n"; say $out "third line"; close $out or die "$out: $!"; print "File saved\n"; sleep($ptime); open (my $in, "<", "output.txt") or die "Can't open output.txt: $!"; + # "<" to read @copyofFC = <$in>; print "Read from file:\n", @copyofFC; } sleep($ptime); {# -- Regular Expressions and capturing print "\n\n"; $email = 'daniel@leguizamon.info'; if ($email =~ /([^@]+)@([^.]+).(.+)/) { print "Username: ", $1, "\n"; print "Server: ", $2, "\n"; print "Extension: ", $3, "\n"; }else{ say "Nop"; } } sleep($ptime); {# -- Subrutines print "\n\n"; sub square{ my $a = shift; +# Shift function by default gets @_ which is the arguments array my $result = $a*$a; return $result; # r +eturn is optional } say square($term->readline('Number to be squared: ')); } sleep($ptime); {# -- Here documents print "\n\n"; + # "" and '' rules apply. But strangely only set at statement (next +line) my $message = <<"ENDofMESSAGE"; # to cr +eate a string that spreads on multiple lines and preserves white spac +es and new-lines Dear $fruits[0], I know you are feeling $fruit_colors{$fruits[0]} but let me tell you I am $fruit_colors{$fruits[1]}. Regards, $fruits[1] ENDofMESSAGE # end of the s +tring exactly as it was at the beginning. No white-spaces before, and + no white spaces after. print $message; } {# -- executing cmd commands print "\n\n"; sleep($ptime); # -- Large comment block =begin comment print "this will NOT be printed"; method | use if ... ------------------------------------------------------------------ +------------- system() | you want to execute a command and don't want +to capture/store its output exec | you don't want to return to the calling perl +script backticks | you want to capture the output of the command open | you want to pipe the command (as input or out +put) to your script =end comment =cut print "executing ping to google.com not storing its output"; sleep($ptime); system("ping", "google.com", "-n", "1"); # system(" +command", "arg1", "arg2", "arg3"); print "\nPing failed: ", $!, "\n" if($? == 256); print "\nPing exited with value ", $? >> 8 unless ($? == 256); sleep($ptime * 2); print "\n\nexecuting pong to 10.10.1.1 and exiting hw.pl"; sleep($ptime); exec("pong", "10.10.1.1", "-n", "1"); # exec("comma +nd", "arg1", "arg2", "arg3"); print "\nPong failed: ", $!, "\n\n"; sleep($ptime * 2); print "executing png to yahoo.com capturing STDOUT\n"; sleep($ptime); my $result1 = `png yahoo.com -n 1`; # $ + context returns a single string, @ context returns a list of lines o +r an empty list if the command failed. #print "\nPing failed: ", $!, "\n" if($? == 256); #print "\nPing exited with value ", $? >> 8 unless ($? == 256); print "\nThis was stored in result1:\n $result1\n"; sleep($ptime * 2); print "\nexecuting png to yahoo.com capturing STDOUT and STDERR\n"; sleep($ptime); my @result2 = `png yahoo.com -n 1 2>&1`; # to collect m +essages sent to STDERR, 2>&1 redirects STDERR to STDOUT #print "\nPing failed: ", $!, "\n" if($? == 256); #print "\nPing exited with value ", $? >> 8 unless ($? == 256); print "\nThis was stored in result2:\n @result2\n"; say @result2[1]; } system ('pause');

Replies are listed 'Best First'.
Re: PAR::Packer error
by dasgar (Priest) on Jan 18, 2016 at 07:47 UTC
    Does anyone know anything about this error?

    Based on your description and the error message that you posted, it looks like the pp utility attempted to delete a temporary file and ran into an issue. Have you tried creating the executable again to see if you get a similar error message?

    The real path has my full name as supposed to DANIEL~1.LEG.

    Actually, that probably is the correct path, but just in DOS 8.3 format. Try searching for "Windows short file name" for more informatin.

    When I execute C:\>pp -o packed.exe hw.pl...

    I'd recommend getting into the habit of using -x and/or -c options so that the pp utility will "determine additonal run-time dependencies" of the script and include them in the stand alone executable that it makes.

      Hi dasgar, Thanks for your reply.

      Have you tried creating the executable again to see if you get a similar error message?

      Yes, it happens every time I create an executable. Note that the executable is created and runs with no issues.

      that probably is the correct path, but just in DOS 8.3 format

      You are correct. It is the short path.

Re: PAR::Packer error
by Athanasius (Archbishop) on Jan 18, 2016 at 07:31 UTC

    Hello drli611, and welcome to the Monastery!

    This looks like it could be a re-appearance of PAR::Packer Bug #29933, which was marked “resolved” in 2007. However, you’ll need to supply more information before the monks can investigate. Specifically, what are the contents of file hw.pl? (We need a short, self-contained example script with which we can replicate the problem. A simple Hello, world! script packed with PAR::Packer works ok on my system, which is similar to yours.)

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Hi Athanasius,

      I have uploaded the script. It is a compilation of tutorials I have been thru.

      Cheers,

        Hello again drli611,

        I’ve successfully wrapped your script with PAR::Packer and run it on my system, without problem. (There are a couple of warnings you should attend to, but that’s not relevant here.) For the record, my environment is as follows:

        • Windows 8.1, 64-bit
        • Strawberry Perl: This is perl 5, version 22, subversion 1 (v5.22.1) built for MSWin32-x64-multi-thread
        • PAR::Packer version 1.029
        • File::Temp version 0.2304

        So, as dasgar says, it looks like a permissions issue. The error you report is Error removing C:/Users/DANIEL~1.LEG/AppData/Local/Temp/parl_MCNJgn.exe at C:/Strawberry/perl/lib/File/Temp.pm line 762, <DATA> line 1., and the relevant line in File::Temp is:

        unlink $file->[1] or warn "Error removing ".$file->[1];

        so the message is actually a warning indicating that the call to unlink failed. I’m sorry, I can’t explain why this is happening, but hopefully one of the other monks will know.

        Anyway, hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: PAR::Packer error
by stylechief (Beadle) on Feb 16, 2016 at 22:08 UTC

    Hi drli611,

    I just encountered this issue, and discovered it was because the executable that I was trying to write with pp was a hidden file. There were other components this program interacted with that were also hidden.

    If I first either deleted the previous version of the executable, or unchecked the hidden checkbox in the EXEs properties (Windows, obviously) the issue went away.

    I can't say if this is the exact same issue you are experiencing, but the message was similar.

    SC