capturing system exit status

O

oscartheduck

Hi folks,

in a program I'm writing I have several commands I pass to the unix OS
underneath the code.

I want to perform error checking to make sure that the OS commands'
exit gracefully, but I'm not seeing a simple python module to do this.
The closest I can see is system(), as detailed here:
http://www.python.org/doc/2.1.3/lib/os-process.html, but I can't
formulate a way to use it.

What I want is a simple if statement such that:

if ExitStatusIsBad:
sys.exit()
else:
go on to next code chunk
 
M

Michael Hoffman

oscartheduck said:
in a program I'm writing I have several commands I pass to the unix OS
underneath the code.

I want to perform error checking to make sure that the OS commands'
exit gracefully, but I'm not seeing a simple python module to do this.

If you're using Python 2.5, you can use subprocess.check_call() which
will raise CalledProcessError for nonzero exit code. If you're using
Python 2.4, you can use retcode = subprocess.call() and check it yourself.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top