Exit status from perl script

A

Adam-the-Kiwi

Hi All,

Fairly newbie question - apologies in advance if this is covered in
FAQs, but I can't find it on CPAN or perldoc.

Essentially, I'm writing a perl script to do some ClearCase trigger
processing. This trigger will fire on a variety of ClearCase actions
and execute a perl script - perl because of the ease of writing
functionality that works on UNIX and Windoze platforms.

I've written a little wrapper to simulate the trigger firing to allow
me to test my funtionality on my laptop at home, which doesn't have
ClearCase installed. Essentially, all this does is set the appropriate
environment variables and then calls the perl script, testing for the
returned value. The perl script in question does some stuff, calls a
subroutine and then passes that subroutine's return value (0 for
success) back up using exit. The wrapper simply prints out the
returned value so I can make sure that the processing is working as it
should.

Except that it doesn't. What I suspect is happening is that I'm
testing the return value of 'perl' rather than the script it executes.
Is that right? Can I access the scripts' return value instead?

Note: it doesn't really matter, because, as you can see, I'm printing
out the return anyway - I'm just curious, like...

Cheers - Adam...

Cradle:
#===============================================================================
#
# Name: trigger_wrapper.pl
# Author: Adam Cheney
# Description: wrapper for testing triggerware
#
#===============================================================================

use strict;
#use diagnostics;

# Set environment up:

$ENV{'CLEARCASE_OP_KIND'} = 'checkin';
$ENV{'CLEARCASE_TRTYPE_KIND'} = 'pre-operation';
$ENV{'OS'} = undef;
$ENV{'CLEARCASE_ELTYPE_NAME'} = 'file';
$ENV{'CLEARCASE_COMMENT'} =
'(AWC)8954-GXS;15599-CXM;17273-SDF;S4012-GXT: another good one.\n';
$ENV{'CLEARCASE_USER'} = undef;

my $system_return = system ("perl IMtrig.pl");

print "\nReturn value is: $system_return";



Perl script:
#===============================================================================
#
# Name: IMtrig.pl
# Author: Adam Cheney
# Description: Central entry point for all IM trigger processing
#
#===============================================================================

use strict;
#use diagnostics;
use ETCccutil;
use ETCtrigfunc;

# Define location of exported DID text file
my $DID_file = "cds_28Oct_17h41.txt";

# Define reference to anonymous hash laying out actions matrix
my $matrix = {'checkout' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'checkin' => {'preop' => \&ETCtrigfunc::precheckin,
'postop' => \&ETCtrigfunc::noaction},
'mkelem' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'uncheckout' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'reserve' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'unreserve' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'chevent' => {'preop' => \&ETCtrigfunc::noaction,
'postop' => \&ETCtrigfunc::noaction},
'rmelem' => {'preop' => \&ETCtrigfunc::prermelem,
'postop' => \&ETCtrigfunc::noaction},
'rmver' => {'preop' => \&ETCtrigfunc::prermver,
'postop' => \&ETCtrigfunc::noaction},
'rmbrnach' => {'preop' => \&ETCtrigfunc::prermbranch,
'postop' => \&ETCtrigfunc::noaction}};


my $action = ""; # The action that invoked the trigger
my $sequence = ""; # preop or postop

($action, $sequence) = &ETCccutil::gettrigger;

# Call the appropriate function
my $trigreturn = &{$matrix->{$action}->{$sequence}} ($DID_file);

print "...and the return value is $trigreturn\n";
exit ($trigreturn);
 
M

Mark Clements

Adam-the-Kiwi wrote:

I've written a little wrapper to simulate the trigger firing to allow
me to test my funtionality on my laptop at home, which doesn't have
ClearCase installed. Essentially, all this does is set the appropriate
environment variables and then calls the perl script, testing for the
returned value. The perl script in question does some stuff, calls a
subroutine and then passes that subroutine's return value (0 for
success) back up using exit. The wrapper simply prints out the
returned value so I can make sure that the processing is working as it
should.

Except that it doesn't. What I suspect is happening is that I'm
testing the return value of 'perl' rather than the script it executes.
Is that right? Can I access the scripts' return value instead?
my $system_return = system ("perl IMtrig.pl");

print "\nReturn value is: $system_return";



Perl script:
# Call the appropriate function
my $trigreturn = &{$matrix->{$action}->{$sequence}} ($DID_file);

print "...and the return value is $trigreturn\n";
exit ($trigreturn);

You need to (carefully(!)) read the documentation for system:

The return value is the exit status of the program
as returned by the "wait" call. To get the actual
exit value shift right by eight (see below). See
also "exec".

eg

bob 761 $ perl -l
$ret=system("perl", "-le","exit(123)");print $ret>>8
123
bob 762 $

regards,

Mark
 
A

adamomitcheney

Mark said:
Adam-the-Kiwi wrote:





You need to (carefully(!)) read the documentation for system:

The return value is the exit status of the program
as returned by the "wait" call. To get the actual
exit value shift right by eight (see below). See
also "exec".

eg

bob 761 $ perl -l
$ret=system("perl", "-le","exit(123)");print $ret>>8
123
bob 762 $

regards,

Mark

I had read the documentation and although I wasn't shifting the result,
I was only looking for a non-zero result to be returned, so I thought
the bit shift shouldn't really matter. What was coming back, though,
was zero (every time) - daftly, I had failed to realise that the two
non-zero values that my script was producing were 256 or 512,which
would always produce zero: D'OH!

Sorted now. Thanks for the help, Mark.

Adam...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top