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-22-2016, 11:06 AM
Tekky Tekky is offline
Registered User
 
Join Date: Apr 2016
Posts: 9
How to stop a python script w/o subroutines or before subs

If I perform a check at the very beginning of a python script, prior to the Main() (outside a subroutine), or create a script without subs, is there a way to stop the script without exiting SecureCRT completely?

The only way I've found to stop a script in this manner is using "crt.Quit()", but that completely exits secureCRT, which I don't want.

Any suggestions?

Regards,
Tek
Reply With Quote
  #2  
Old 04-22-2016, 11:27 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 998
crt.Screen.SendSpecial("MENU_SCRIPT_CANCEL")

Does that work for you?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 04-22-2016, 11:37 AM
Tekky Tekky is offline
Registered User
 
Join Date: Apr 2016
Posts: 9
Doesn't look like:

I created a 2 line script test.py

crt.Screen.SendSpecial("MENU_SCRIPT_CANCEL")
crt.Dialog.MessageBox("Script did not stop")

It shows me the second line dialog box...

Regards,
Tek
Reply With Quote
  #4  
Old 04-22-2016, 11:57 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 998
SecureCRT's scripting support is threaded, so the cancel may take some non-zero time to be realized. You'll notice that even when the "Script did not stop" message appears, there is also a notice telling you that the script was indeed canceled.

If you put a crt.Sleep(200) (or even smaller value) after your SendSpecial(), does it work better for you?

Then, if you weren't too averse to creating a sub in python, you could define one at the very top of your script code, and use it throughout, as needed:

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


#...
#...
#...

crt.Dialog.MessageBox("Press OK to cancel the script.")
CancelScript()
crt.Dialog.MessageBox("Script did not stop")

#...
#...
#...
--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 04-22-2016, 12:17 PM
Tekky Tekky is offline
Registered User
 
Join Date: Apr 2016
Posts: 9
I use subs, I sorta ran into this by accident and was curious how to stop a script outside a sub.

Thanks for the info. Now if you could help me with my other question...

https://forums.vandyke.com/showthread.php?t=12334

Appreciate the great help!
Reply With Quote
  #6  
Old 04-22-2016, 01:14 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 998
Quote:
Originally Posted by Tekky View Post
Thanks for the info. Appreciate the great help!
You're welcome.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

Tags
python quit exit


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 06:30 AM.