I'm a newbie when it comes to writing code and I have a trouble finding solution to what seems is rather easy problem. I'm writing a code that will check output of another program, and will take action in response to what this other executing program is outputting. The other program saves me log in .txt format as an output. I want to open this file check for keywords like: "Error", "Warning" or "Completed" and then process further. here are three options for this output file to have:
- Error
- Completed, but some warning or error still occurred
- Copleted without problems
In first two cases I want the program to just restart the whole process, and if all is good to close itself and save final log.
First process comes to close and I have a log_1. I open it and search for keywords:
if message_complete in log_1:
if message_error or message_warning in log_1:
print("Saving log_2")
print("Program finished, but errors occurred, restarting application")
else:
print("Saving log_2")
print("Program finished, closing aplication")
else:
print("Saving log_2")
print('Program not executed properly, restarting application")
In case of nested if stament being true I want to exit to same place as if first if is not true. My goal is to make 3 tries and then reset the application, ending with 3 different logs that can be searched in for keywords. I searched for something like goto statement (which I know not to use). I know that break doesn't work in if statements. Is there an easy way out of this problem?