exit status

J

Jerry Adair

Ok I'll keep with my vane of asking potentially obvious questions.

I am attempting to return an error code from a Perl script. At first blush,
it seemed easy with the exit() call. But it doesn't work. Just out of
frustration I tried a return() call, and I got the correct return code,
albeit with an error message about returning from a non-subroutine.

The code I had was simple enough:

exit(status( <blah blah blah> ));

Thank you in advance.

Jerry
 
A

Andrzej Adam Filip

Jerry Adair said:
Ok I'll keep with my vane of asking potentially obvious questions.

I am attempting to return an error code from a Perl script. At first blush,
it seemed easy with the exit() call. But it doesn't work. Just out of
frustration I tried a return() call, and I got the correct return code,
albeit with an error message about returning from a non-subroutine.

The code I had was simple enough:

exit(status( <blah blah blah> ));

How do you test the value of exit code?
[ What OS do you use? ]

It *works* as expected on my linux:
perl -e 'exit 2' ; echo $?
 
J

J. Gleixner

Jerry said:
Ok I'll keep with my vane of asking potentially obvious questions.

I am attempting to return an error code from a Perl script. At first blush,
it seemed easy with the exit() call. But it doesn't work. Just out of
frustration I tried a return() call, and I got the correct return code,
albeit with an error message about returning from a non-subroutine.

The code I had was simple enough:

exit(status( <blah blah blah> ));

Maybe one of these will help:

perldoc -f die
perldoc -f exit
perldoc -f eval
perldoc -f system

It sounds like you should be using die or exit, so the issue seems to be
in how the program that's calling the script is detecting the error. It
should look at the exit status, not what's returned on STDOUT.

If you're still stuck, show us how you're calling the script and how
you're getting the 'error code'. A simple one liner that calls the
script/subroutine that has one line of code (die or exit) should be
enough to figure it out.
 
P

Paul Lalli

Jerry said:
Ok I'll keep with my vane of asking potentially obvious questions.

Your problem is not with the obviousness of the question, but of the
complete lack of necessary information provided.
I am attempting to return an error code from a Perl script. At first blush,
it seemed easy with the exit() call. But it doesn't work.

Yes it does. Come on. Do you really think that exit() is somehow
broken in the language, and you're just the first person to ever
notice?

Perhaps you could tell us exactly *how* you're determining that it
"doesn't work"?

Have you read the posting guidelines for this group yet? They contain
excellent advice and information on how to get the most help possible
from this group.

Paul Lalli
 
J

Jerry Adair

Paul-

Not sure why I am getting the flack from you, but whatever. The question
seemed simple enough to me, I never said that exit() was broken. Sheesh.

Anyway, I have read the documentation and know about the return value from
wait, etc. To answer the other questions I have been asked, I am using
system() calls to invoke the script.

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. From doing more reading in the Camel (yes, I
have already read all of the function descriptions that the other poster
suggested, I did try to solve this one on my own before coming here, believe
it or not) exit() doesn't actually exit straight away, but it calls some END
routines (I don't have any of those defined) which might change $? - perhaps
that is part of the problem.

Curiously, I changed the system() call in script "2" to an exec() call, and
I get the correct return value in script "1", namely the number 2.

I hope this helps. Any more flack and I think I'll punt and seek help
elsewhere.

Thanks,

Jerry
 
P

Paul Lalli

Jerry said:
Not sure why I am getting the flack from you, but whatever.

Please explain what flack you think I've given you.
The question
seemed simple enough to me, I never said that exit() was broken. Sheesh.

You didn't? Allow me to re-arrange your top posting (have you read the
Posting Guidelines yet?) and show you what you posted:

Sure as heck seems to me like you just said exit() doesn't work. Where
am I mistaken?
I hope this helps. Any more flack and I think I'll punt and seek help
elsewhere.

I find this statement very interesting, on multiple levels. First,
it's phrased as though you're somehow threatening me, as though I'll be
damaged if you stop posting here. I don't understand what would make
you think that. Secondly, I still don't get what "flack" you think
I've given you. You posted a very incomplete problem statement, with
absolutely no code to back up what you said, and I pointed out to you
how it's not possible to help you effectively without those two things.
Where is the problem?

I suggest you grow a little bit of a spine.

(Now see, *that* was flack)

Paul Lalli
 
D

Dr.Ruud

Jerry Adair schreef:
Paul-

Not sure why I am getting the flack from you, but whatever.

Come on, Jerry. You don't follow the Posting Guidelines, you top-post,
you leave old text that you don't reply on, you hide your questions in
boring layers, and still there are people left here that are willing to
help you, so it must be Friday.

Please first read the Posting Guidelines now, they are there to help you
help yourself.

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

This is not actual code that we can run. You should copy/paste exactly
the code that you run yourself.

You don't check for -1, you don't print $!.
 
P

Paul Lalli

Jerry said:
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
 
X

xhoster

Jerry Adair said:
Paul-

Not sure why I am getting the flack from you, but whatever.

His flack was self-documenting. And now we can odd top-posting to
the flack.
Anyway, I have read the documentation and know about the return value
from wait, etc. To answer the other questions I have been asked, I am
using system() calls to invoke the script.

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,

That is strange. The output of script 2 should give a zero, or a number
greater than 255. But anyway, if it actually is 2, then 2>>8 is zero, so
script 2 itself is exiting with zero. That would certainly explain the
result, no?


I hope this helps. Any more flack and I think I'll punt and seek help
elsewhere.

No skin off of my nose, certainly.

Xho
 
A

A. Sinan Unur

[ Do not top-post ]
Not sure why I am getting the flack from you, but whatever. The
question seemed simple enough to me, I never said that exit() was
broken. Sheesh.

Anyway, I have read the documentation and know about the return value
from wait, etc. To answer the other questions I have been asked, I am
using system() calls to invoke the script.

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. From doing more reading in the
Camel (yes, I have already read all of the function descriptions

It does not look like you have read

perldoc -f system

Sheeesh.
I hope this helps. Any more flack and I think I'll punt and seek help
elsewhere.

That's up to you. We are indifferent.


Ditto

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
T

Tad McClellan

Jerry Adair said:
Any more flack and I think I'll punt and seek help
elsewhere.


That probably won't be needed, as many regulars will have already
killfiled you due to your bad attitude and blatant rudeness.



[ snip TOFU ]
 
A

Arndt Jonasson

Paul Lalli said:
Sure as heck seems to me like you just said exit() doesn't work. Where
am I mistaken?

Perhaps "it" = "attempting to return an error code from a Perl
script", not "it" = "the exit() call".
 
P

Paul Lalli

Arndt said:
Perhaps "it" = "attempting to return an error code from a Perl
script", not "it" = "the exit() call".

I'm not seeing the distinction, since exit() *is* how you return an
error code from a Perl script.

Paul Lalli
 
A

Arndt Jonasson

Paul Lalli said:
I'm not seeing the distinction, since exit() *is* how you return an
error code from a Perl script.

"Attempting" was the operative word.
 

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

Forum statistics

Threads
474,265
Messages
2,571,071
Members
48,771
Latest member
ElysaD

Latest Threads

Top