Packed executable exit code 1 issue

Deepak Khosla via par <[email protected]> Sat, 15 Jul 2023 20:14:12 +0000
Newsgroups gmane.comp.lang.perl.par
Message-ID <SA1PR16MB4635BA45E3A0C82C96AD268EFF35A@SA1PR16MB4635.namprd16.prod.outlook.com>
Hi,
I am using perl v5.36 and PAR:Packer 1.057 and would appreciate some insigh=
t into the exit code behavior as seen by the OS. Question at the end:

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

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

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, ? =3D 2
[dkhosla]$ echo $?
2

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

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

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

I saw a note about trying 'POSIX::_exit' and that does fix the issue; but d=
oing that noticed that STDOUT etc. is not fully flushed.
The questions are:=20
- Should I be using 'POSIX::_exit' or there is a fix to the issue shown usi=
ng 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,=20
Deepak Khosla=20
eXcellence in IS Solutions, Inc. (X-ISS)=20
Email : [email protected]=20