Read output and input each line separately - Python/SecureCRT
Question: I am trying to get a Python script to read the output of a command, then to
run multiple commands based on the list it receives. I don't generally write
VBS or Python, so I'm getting stuck. (it's ugly)

    
    
    def Main():
        objTab = crt.GetScriptTab()
        objTab.Screen.Synchronous = True
        objTab.Screen.IgnoreEscape = True
        objTab.Screen.Send("scsi i dev select 1" + chr(13))
        objTab.Screen.WaitForString("============")
        szPrompt = ">"
        szResult = objTab.Screen.ReadString(szPrompt)
        crt.Dialog.MessageBox(szResult)
        crt.Screen.Send("scsi i gen" + (szResult) + "w 0 100 1 0")
    
    Main()
    

The input is working (albeit, I wish it would ignore the beginning of the >
text (`sn200028` in this case). It's not important that it does though.

![enter image description here](http://i.stack.imgur.com/Uzwmg.png)

The next 2 parts I am stuck on, namely:

Part 1. How to get it to send the correct output. The correct output should
be:

    
    
    scsi i gen X w 0 100 1 0
    

where `X` is one of the numbers in this list.

Part 2. I need it to actually send this command for each item in the list. Not
the whole list as `X`.

Any help is appreciated. Right now we have to copy and paste the lists, then
awk them into another list, which is then cut and pasted. It would be much
more beneficial to just run this from SecureCRT.


Answer: Solved

    
    
    def Main():
        objTab = crt.GetScriptTab()
        objTab.Screen.Synchronous = True
        objTab.Screen.IgnoreEscape = True
        objTab.Screen.Send("scsi i dev select 1" + chr(13))
        objTab.Screen.WaitForString("============")
        objTab.Screen.Send(chr(13))
        szPrompt = "s"
        szResult = objTab.Screen.ReadString(szPrompt)
        result = crt.Dialog.MessageBox('Press OK to erase the first 100 blocks of the following devices: \n' + (szResult) , 'Run?' , ICON_QUESTION | BUTTON_YESNO | DEFBUTTON2)
        if result == IDNO:
            return
        if result == IDYES:
            vList = szResult.splitlines()
        for strString in vList:
            crt.Dialog.MessageBox('scsi i gen' + (strString) + ' w 0 100 1 0' + chr(13))
    
    Main()
    

I was able to use str.splitlines in order to split each line then add it to
the messagebox.

