0

I have a python script that searches through a directory, and if any files were recently modified, it executes a command to run our modeling software along with another python script and generate a report. I have the report running currently, and I want to add on a section that if the report generation for some reason was aborted (the software didn't open, there was some error, etc), I want to know and send an email out stating that the run did not complete. Currently I have this below, but I realized that it returns zero since running the actual command worked, even if the report was not generated.

    ansa_call = "ansa_15.1.0 -nogui -exec       
    load_script:/path/SubstructureSummary.py -exec 'SubstructureSummary (\""+path+"\")'"
    print ansa_call
    ret = os.system(ansa_call)
    print ret
    if ret != 0:
            print 'sending email'

I have injected an error into the secondary script 'SubstructureSummary.py' so that it will be forced to err. How do I grab a return value that shows the incomplete run?

Thank you!!

2
  • Since it is ansa that is executing your script (and not the system call directly), it is the return value of ansa_15.1.0 you are capturing in ret, not the return value of the secondary script. Your question is really: How do I have ansa return a non-zero return code if any error is returned during load_script execution. Commented Oct 16, 2014 at 20:59
  • thanks, that's a good thought. I'll start looking in that direction. Commented Oct 16, 2014 at 21:05

1 Answer 1

1

You say your script produces a report. If this is a file and you know where it should be, then maybe the easiest and most robust way would be to do some checks to see if the output file looks OK? Maybe check the timestamp, the file size, or other checks?

If the file is not there, or it looks corrupted, you send the email.

Sign up to request clarification or add additional context in comments.

1 Comment

silly me. I got too bogged down and totally forgot the obvious solution. So ridiculous! Ha! Thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.