python with echo

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Nov 13 02:49:08 CET 2009


On Thu, 12 Nov 2009 19:30:01 +0000, MRAB wrote:

>> I don't understand that. Exit status codes on all systems I'm familiar
>> with are limited to 0 through 255. What operating system are you using?
>> 
>> Assuming your system allows two-byte exit statuses, you should check
>> the documentation for echo and the shell to see why it is returning
>> 256.
>> 
> In some OSs the exit status consists of 2 fields, one being the child
> process's exit status and the other being supplied by the OS.

Which OSes?

> The reason is simple. What if the child process terminated abnormally?
> You'd like an exit status to tell you that, 

Which it does. Anything other than 0 is an error. I see that, for 
example, if I interrupt "sleep 30" with ctrl-C instead of waiting for it 
to exit normally, it returns with an exit status of 130.

[steve at soy ~]$ sleep 3  # no interrupt
[steve at soy ~]$ echo $?
0
[steve at soy ~]$ sleep 3  # interrupt with ctrl-C

[steve at soy ~]$ echo $?
130

I get the same result on a Linux box and a Solaris box, both running bash.



> but you wouldn't want it to
> be confused with the child process's own exit status, assuming that it
> had terminated normally.

I don't understand what you mean here. Why are you assuming it terminated 
normally if it terminated abnormally?




-- 
Steven



More information about the Python-list mailing list