Hi,
I have several applications using a function
sub DieWithCode {
my $numerical_exit_code = shift;
my $msg = shfit;
# do something with $msg (inserting application name, linebreaks... i
+f necessary
exit ($numerical_exit_code);
}
worked fine also when I packed the application using pp (PAR::Packer) into a self-extracting binary.
Both under Windows (Strawberry Perl 5.22 ) and Linux (5.22 too).
Then I moved the essential part of the code of one application into a sub into a module.
Let's call this
sub AppAction (parameters)
Still everything worked fine.
But:
In another interactive application (command line, shell like) I want to execute this function WITHOUT the whole program exiting in
case of an error where the application packed into the sub would normally exit.
OK.
Changed DieWithCode to
sub DieWithCode {
my $numerical_exit_code = shift;
my $msg = shfit;
# do something with $msg (inserting application name, linebreaks... i
+f necessary
if ($^S) {
$EXITCODE = $numerical_exit_code; # module global var
die ($msg);
}
print $msg;
exit ($EXITCODE);
}
So the function would die in case of
eval { AppAction (myParameters)}
and exit when I embed the call into a standalone program/script.
So when I call it using eval:
my $e;
{
local $@;
my $result = eval { AppAction (\%opt ) };
if (!defined $result) { # died...
$e = $@;
printf "result : %s, e : %s\n", defined $result?sprintf "%d",
+$result: 'undef', $@;
}
chomp $e;
}
printf "AppAction failed ($e)\n" if $e;
$EXITCODE = 0;
I can see AppAction dying, being caught by eval and the main (interactive app) would continue
regardless of executing perl mainapp.pl or execute ./main_app (binary)
BUT: When I call AppAction as a function in the standalone version:
AppAction (%opt);
there's a difference
perl mainapp.pl exits (correctly)
but
./main_app dies, as if AppAction would have been eval'ed.
SO MainApp would stop/die
Can somebody explain this? And/or give me some hints how to correct this.
I already had a look into PAR.pm but could not see that the packed script is eval'ed.
The main reason I came across his strange behavior of the packed binary is:
In a GNU Make file I added a target for testing the packed binary.
Doing some basic invocations, like -? for help or a simple action that also exits with EXITCODE=0 the
make is stopping after the first invocation, due to errorlevel 255 (set by perl as result code for a die)
even when I set the exitcode $? in an END block to 0.
When I change the execute BINARY
parameters to a perl APP_SCRIPT.pl
parameters everything works fine...
This is the second strange thing happening
Thanks
Axel
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.