VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Existing Script from Within Function (https://forums.vandyke.com/showthread.php?t=13517)

krypton179 04-26-2019 10:37 AM

Existing Script from Within Function
 
Hi Experts,

I am looking for some further details of how I can exit an active script from within a function without logging the script path and line number.

Looking at earlier threads I found this logic, which works:

def CancelScript()
crt.Screen.SendSpecial("MENU_SCRIPT_CANCEL")
crt.Sleep(1)

However, instead of opening a dialog box, I would like to exit the script without printing anything to the screen.

I looked into using the crt.Quit() option, but this closes CRT completely.

Are there any alternatives which I can use to accomplish this?

Kind Regards,

K

jpellegrini 04-26-2019 11:44 AM

Hi krypton179,

Unfortunately, there is currently not a way to disable the "Script Cancelled" dialog when a script is cancelled.

However, I have added this thread to a feature request in our product enhancement database for an option to disable the "Script Cancelled" dialog. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #13517" in the subject line or use this form from the support page of our website.

gregg 06-07-2019 12:57 PM

use try/except
 
sys.exit(0) causes an error, but you can raise an Exception to abort a function up to a try/except block and then do nothing with the exception.

Example:

Code:

# $language = "Python"
# $interface = "1.0"

# By having a specific exception to look for,
# other exceptions won't be ignored.
class EarlyExit(Exception):
    pass

def func2():
    crt.Dialog.MessageBox("About to exit script early", "Bye")
    raise EarlyExit()

def func1():
    func2()


def main():
    try:
        func1()
        crt.Dialog.MessageBox("Should not see this", "Wut")
    except EarlyExit:
        pass

main()



All times are GMT -6. The time now is 02:23 PM.