Re: exit status



Jerry Adair wrote:
inside script "1":
my $exitStatus = system( "<call to script #2>" );
print( STDOUT "exit=$exitStatus\n" );

inside script "2": (similar code)
my $return = system( "<call to a program>" );
print( STDOUT "return=$return\n" );
exit( $return >> 8 );

And the output from script "2" gives the number 2, whereas the output from
script "1" gives the number 0.

If the output from script 2 gives you 2, that means that $return is
equal to 2. But then you're shifting 2 to the right 8 bits, and
exiting with that status. That's the status that gets returned to
$exitStatus. You need to be consistant when grabbing these exit
statuses and shifting them.

Here is a series of short-but-complete scripts (as recommended by the
Guidelines - have you read them yet?) that demonstrates how this
works....

$ cat ret2.ksh
#! /bin/ksh
echo "In ret2.ksh"
exit 2;

$ cat call_ret2.pl
#!/usr/bin/perl
use strict;
use warnings;

my $return = system('ret2.ksh');

print STDOUT "return=", ($return >> 8), "\n";
exit ($return >> 8);

$ cat call_call_ret2.pl
#!/usr/bin/perl
use strict;
use warnings;

my $exitStatus = system('call_ret2.pl');
print STDOUT "exit=", ($exitStatus >> 8), "\n";

$ ./call_call_ret2.pl
In ret2.ksh
return=2
exit=2

$

Seems clear to me that exit and shifting both work as they're supposed
to. Now, can you create equally short-but-complete scripts that
demonstrate your error? If so, it's quite likely someone will be able
to help you.

Paul Lalli

.



Relevant Pages

  • Re: Changing a users password non-interactively?
    ... You need expect and a setpass.expect script which ill add ... exit with a nasty warning. ... # Be careful of the COMMAND and UNDOCMD - they are dependant on your ...
    (comp.unix.aix)
  • Re: script does not always work the same each time.
    ... I have written a simple script to test code build and test run on a ... $lineterminationChar {append output $expect_out; ... exit 1;} ...
    (comp.lang.tcl)
  • Re: OSR505 Signal trapping in shell scripts
    ... >>My test script is at the end. ... > process only gets one SIGHUP per fd. ... > end up doing ioctls on fd 0, which is your stopio'd telnetd pty. ... > of the exit function. ...
    (comp.unix.sco.misc)
  • Re: How to time out a command
    ... > I have a ksh script that calls another utility (command A). ... I once made the following script to do exactly that. ... # Runs a command and kills it, if necessary, after a given timeout. ... # 0<c<127 - job exited with this exit code ...
    (comp.unix.shell)
  • Re: Changing a users password non-interactively?
    ... You need expect and a setpass.expect script which ill add ... exit with a nasty warning. ... # Be careful of the COMMAND and UNDOCMD - they are dependant on your ...
    (comp.unix.aix)