in reply to Re: exit value not passed back
in thread exit value not passed back

Here is the full code I used (I have tried also the fork-exec method) but no luck:

### Calling.pl
#!/usr/local/bin/perl -w

#eval { system ("./called.pl"); };
#$exit_value = $?;

#$exit_value = system ("./called.pl");

if ($pid2 = fork) {
# parent catches INT
print "IN PAR\n";
local $SIG{INT} = sub { print "In parent ...wait\n" };
waitpid ($pid2, 0);
}
else {
die "cannot fork: $!" unless defined $pid2;
eval { exec ("./called.pl"); };
}

print "\nE-at = $@\n";
print "\nE-! = $!\n";

print "\nE = $exit_value\n";

$exit_value = $exit_value >> 8; # Get the higher byte which has the real exit value
print "\nE1 = $exit_value\n";


### called.pl
#!/usr/local/bin/perl -w

if (@ARGV) {
$SIG{INT} = \&exit_gracefully;
for(1..10){
warn "called sleeping $_";
select undef, undef, undef, 0.5;
}
exit 1;
} else {
warn "calling system\n";
system ( $^X, __FILE__ , 'called');

$exit_val = $? >> 8;

warn "\n exit_val $exit_val";
}

sub exit_gracefully
{
$SIG{INT} = \&exit_gracefully;
print "@ARGV Program interrupted .. \n";
exit (3);
}

###Output.txt

IN PAR
calling system
called sleeping 1 at ./called.pl line 6.
called sleeping 2 at ./called.pl line 6.
called sleeping 3 at ./called.pl line 6.
called sleeping 4 at ./called.pl line 6.
^Ccalled Program interrupted ..
In parent ...wait

exit_val 3 at ./called.pl line 16.

E-at =

E-! = Interrupted system call
Use of uninitialized value in concatenation (.) or string at ./calling.pl line 22.

E =

Use of uninitialized value in right bitshift (>>) at ./calling.pl line 24.

E1 = 0