views:

35

answers:

3

Hi all.

I have a python script that invokes the following command:

# make

After make, it also invokes three other programs. Is there a standard way of telling whether the make command was succesful or not? Right now, if make is successful or unsuccessful, the program still continues to run. I want to raise an error that the make was not possible.

Can anyone give me direction with this? Thanks, friends.

+2  A: 

The return value of the poll() and wait() methods is the return code of the process. Check to see if it's non-zero.

Ignacio Vazquez-Abrams
Is poll() and wait() build into python or make?
Carlo del Mundo
`poll` and `wait` are methods understood by `subprocess.Popen` objects. Click the links in Ignacio's answer for more.
unutbu
Thanks for the tip! Didn't even realize it was a link!
Carlo del Mundo
A: 

Look at the exit code of make. If you are using the python module commands, then you can get the status code easily. 0 means success, non-zero means some problem.

Rory
Thanks! I'll look into it
Carlo del Mundo
A: 
import os
if os.system("make"):
    print "True"
else:
    print "False"
Teodor Pripoae
Sorry. I don't think this works. I just tested it out with calling a dummy program that never exists and it never goes to the false statement
Carlo del Mundo
This script will print True if make returned any errors, and false if it exited cleanly.
Teodor Pripoae