develooper Front page | perl.par | Postings from July 2023

Packed executable exit code 1 issue

Thread Next
From:
Deepak Khosla via par
Date:
July 17, 2023 05:56
Subject:
Packed executable exit code 1 issue
Message ID:
SA1PR16MB4635BA45E3A0C82C96AD268EFF35A@SA1PR16MB4635.namprd16.prod.outlook.com
Hi,
I am using perl v5.36 and PAR:Packer 1.057 and would appreciate some insight into the exit code behavior as seen by the OS. Question at the end:

Code:
==========================
use strict;
use warnings;
my $exit_code = $ARGV[0];
print "called with $0 $exit_code\n";

END {
    $? = $exit_code;     #  Setting this in case exit is ignoring our exit_code 
    print STDERR "Exiting final with exit_status $exit_code, ? = $? \n";
    exit ($exit_code);
}
===============================

What is strange is that, running under perl (raw code), all exit codes work i.e. under Linux:
[dkhosla]$ perl t.pl 2
called with t.pl 2
Exiting final with exit_status 2, ? = 2
[dkhosla]$ echo $?
2

[dkhosla]$ perl t.pl 1
called with t.pl 1
Exiting final with exit_status 1, ? = 1
[dkhosla]$ echo $?
1

[dkhosla]$ perl t.pl 0
called with t.pl 0
Exiting final with exit_status 0, ? = 0
[dkhosla]$ echo $?
0

But running the packaged version - I get varied results. The sample code always returns 0 for $? But my bigger piece of code provides proper code for 0 or 2, but a 0 when exiting with a 1. 
[dkhosla]$ ./t 2
called with ./t 2
Exiting final with exit_status 2, ? = 2
[dkhosla]$ echo $?
0

I saw a note about trying 'POSIX::_exit' and that does fix the issue; but doing that noticed that STDOUT etc. is not fully flushed.
The questions are: 
- Should I be using 'POSIX::_exit' or there is a fix to the issue shown using std. perl 'exit' with PAR?
- If POSIX, what other 'cleanup' should I be concerned about taking care of aside from flushing STDOUT etc...?

Thanks for any guidance!

Regards, 
Deepak Khosla 
eXcellence in IS Solutions, Inc. (X-ISS) 
Email : dkhosla@x-iss.com 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About