Thread: VBS to Python
View Single Post
  #3  
Old 06-05-2021, 10:23 AM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 75
This should be an adequate replacement for the mentioned script.

Code:
# $language = "Python3"
# $interface = "1.0"

# Script to open a text file and read it line by
# line to a server.

DEFAULT_FILENAME = r"F:\SecureCRT\sqlScripts\DBA_Feature_usage.sql"

def main():
    # filename = crt.Dialog.Prompt("Filename to read:", "Filename", DEFAULT_FILENAME, False)
    filename = crt.Dialog.FileOpenDialog("Text file", "Open", DEFAULT_FILENAME, "SQL Files (*.sql)|*.sql|All Files (*.*)|*.*|")

    if not filename:
        # escape pressed or no filename entered
        return

    crt.Screen.Synchronous = True
    try:
        # Open a file for reading.
        with open(filename, "rt") as fh:
            for line in fh:
                crt.Screen.Send(line.rstrip() + "\r")
    except FileNotFoundError:
        crt.Dialog.MessageBox("Could not open file %s" % filename, "File not found")
    finally:
        crt.Screen.Synchronous = False
    
main()
Reply With Quote