How can I capture all exceptions especially when os.system() fail? Thanks
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Jun 13 21:38:35 EDT 2007
En Wed, 13 Jun 2007 21:47:16 -0300, mike <needpassion at gmail.com> escribió:
> Following piece of code can capture IOError when the file doesn't
> exist, also, other unknown exceptions can be captured when I press
> Ctrl-C while the program is sleeping(time.sleep). Now the question is:
> when I run the non-exist command, the exception cannot be captured.
> So far so good, then I changed the code to run a non-exist command
> "wrong_command_test"(commented the open and sleep lines), then the
> script printed:
> sh: wrong_command_test: command not found
> well Done
That's because it is not an exception, it is an error message coming from
your shell, not from Python.
You can extract the exit status from what os.system returns (see the
details on the docs for os.system); in particular, usually "command not
found" is error 127
This is a list of more-or-less standard exit codes:
http://www.faqs.org/docs/abs/HTML/exitcodes.html
--
Gabriel Genellina
More information about the Python-list
mailing list