user402642
user402642

Reputation:

Python Script Calling Make and Other Utilities

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 successful 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?

Upvotes: 1

Views: 615

Answers (4)

Frank Kusters
Frank Kusters

Reputation: 2634

Use subprocess.check_call(). That way you don't have to check the return code yourself - an Exception will be thrown if the return code was non-zero.

Upvotes: 0

Teodor Pripoae
Teodor Pripoae

Reputation: 1394

import os
if os.system("make"):
    print "True"
else:
    print "False"

Upvotes: 0

Amandasaurus
Amandasaurus

Reputation: 60649

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.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

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

Upvotes: 1

Related Questions