Is there a command to end running script from within the script?

Asked by Lexen

Hey everyone. Thanks for reading my question.

Is there a command that can end the running script from within the script? The reason why I would like to do this is I would like to have an if else statement, where the else will restart the script and close itself.

Is there a way to do this? Is there a better way of doing it that I don't know about?

Thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

There is an exit(number), but this simply ends the script and has no feature, to restart it again automatically. If you run your script from command line, you can start it again, if the exit number tells you to do so (e.g. 1 signals, to stop and 0 says repeat) using a loop.

But I guess what you need is some loop in the script itself:

while True: #loops forever
    # some of your coding
    if some_condition:
         continue #start all over again at the while
    else:
         if some_other_condition:
             break # jumps out of the while loop
   # more of your coding
# first statement after the loop

see faq 1437 on looping
and faq 1800 about indentation

Revision history for this message
Lexen (lexen1) said :
#2

Sweet! That'll work. I have the script set up as an executable, so I'll just have it run itself, then exit. Something like:

App.open (The Script)
exit (1)

Thanks for all you do! You really keep things moving and I want you know how much you have helped me out here, and in the past!

Revision history for this message
Lexen (lexen1) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Really thanks for kind feedback.

All the best.