Operating System - Linux
1753659 Members
5458 Online
108798 Solutions
New Discussion юеВ

Re: How to know the Exit status of a executable in HP Unix through PERL

 
SOLVED
Go to solution
CA1490051
Frequent Advisor

How to know the Exit status of a executable in HP Unix through PERL

Hi All,

Can any one please help me to solve the below problem.

I have a perl script. In the Perl script i am executing a "a.out" file using the system("./a.out").

But, I want to check whether the a.out terminated normally without causing any "Bus Error" or "Segmentation Fault".

CAn i do this using "$?". If yes what will be the exit status for normal execution. And does this exit status differ for different flavours of UNIX like Linux and SunOs.

thanks in advance
regards
Vikram
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to know the Exit status of a executable in HP Unix through PERL

Hi Vikram:

To obtain the exit value you need to examine the high eight bits of the value returned:

Hence:

# perl -le '$rc=system("/usr/bin/cp");print "exit status = ",$rc>>8'

1

...looks just like you did:

# /usr/bin/cp; echo $?
1

Regards!

...JRF...
Ralph Grothe
Honored Contributor

Re: How to know the Exit status of a executable in HP Unix through PERL

The explanation can be found in either

perldoc -f system

or

perldoc perlvar

if you look for $?
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: How to know the Exit status of a executable in HP Unix through PERL

The explanation can be found in either

perldoc -f system

or

perldoc perlvar

if you look for $?

Except for SIGKILL and SIGSTOP you can implement a signal handler by assigning the special Perl hash %SIG a code ref to the appropriate key which is the respective signal name without the prefix SIG.
Details to %SIG may also be found in perldoc perlvar.
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: How to know the Exit status of a executable in HP Unix through PERL

Webmasters, please remove my first reply.
This only happens because there are minutes between clicking submit and waiting for the server confirmational response.
Madness, thy name is system administration
Steven Schweda
Honored Contributor

Re: How to know the Exit status of a executable in HP Unix through PERL

> This only happens because there are minutes
> between clicking submit and waiting for the
> server confirmational response.

So, don't wait for that. Wait a few seconds,
then re-view the topic. (I open a new window
for the Reply, so it's easy to reload the
original thread's window after Submitting the
reply.)

And when Submit from Preview fails for no
good reason, just back up to the pre-Preview
page, and try Submit from there.

And when it gets all confused by switching
between forums11.itrc.hp.com and
forums12.itrc.hp.com, try editing the URL to
say forums.itrc.hp.com.

And so on ...

The Forum software appears to be garbage, but
figuring out how to work around its many
problems can be viewed as an entertaining
game (if you're easily entertained).