Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-26-2019, 11:37 AM
krypton179 krypton179 is offline
Registered User
 
Join Date: Apr 2019
Posts: 3
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
Reply With Quote
  #2  
Old 04-26-2019, 12:44 PM
jpellegrini jpellegrini is offline
Registered User
 
Join Date: Mar 2019
Posts: 20
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.
__________________
Thanks,
--Jon

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 06-07-2019, 01:57 PM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 53
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()
Reply With Quote
Reply

Tags
python2.7


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:52 PM.