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

Packed executable exit code 1 issue

Thread Next
Deepak Khosla via par
July 17, 2023 05:56
Packed executable exit code 1 issue
Message ID:
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:

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

    $? = $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 2
called with 2
Exiting final with exit_status 2, ? = 2
[dkhosla]$ echo $?

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

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

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 $?

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!

Deepak Khosla 
eXcellence in IS Solutions, Inc. (X-ISS) 
Email : 

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About