exception KeyboardInterrupt and os.system command

Diez B. Roggisch deets at nospam.web.de
Sun Nov 27 19:09:46 EST 2005


jepler at unpythonic.net wrote:
> You can tell by the exit code from system() whether the subprocess
> exited due to a signal.  Consider this code:
>     import os
>     while 1:
>         print os.system("sleep 1")
> unless you happen to hit ctrl-c at the right time, you'll see it print
> "2" (and "0" when the sleep finishes).  The exit code can be interpreted
> according to the waitpid manpage, though I am not sure where the Python
> equivalent of the WIFSIGNALED and WTERMSIG macros are.

Boy, one never stops learning....

But I have some trouble understanding that - when I write a test-script 
that returns 1 as exit-code, os.system returns 256. Inn fact, returnung 
n means that 256*n is returned from os.system.

But 256 is _also_ returned when C-c is used. Any idea why that's the case?

Regards,

Diez



More information about the Python-list mailing list