Reputation: 23
I have python script (installer.py) which runs multiple python and shell programs:
print "Going to run Script1"
os.system("python script1.py")
print "Going to run Script2"
os.system("python script2.py")
But I found that even if script1.py is not run because of its error, it simply moves on to run script2.py.
How to stop the script (installer.py) at the time of script1.py itself..
Upvotes: 1
Views: 385
Reputation: 2762
os.system
will return the exit status of the system call. Just check to see if your command executed correctly.
ret = os.system('python script1.py')
if ret != 0:
# call failed
raise Exception("System call failed with error code %d" % ret)
ret = os.system('python script2.py')
if ret != 0:
# call failed
raise Exception("System call failed with error code %d" % ret)
Upvotes: 1