#1
|
|||
|
|||
SecureCRT problem with instr special characters
My code is below but the problem can probably be explained quicker:
Using instr while searching for special characters seems not to work, I've tried the following variations: instrrev(1, szResult, Cstr(chr(34))) instrrev(1, szResult, chr(34)) instrrev(1, szResult, """) instrrev(1, szResult, '"') instrrev(1, szResult, \") and many others, nothing works. Even other special characters seem to fail... the other one I've tried is the "/" symbol. Always fails with the same error: Microsoft VBScript runtime error Error: Type mismatch: '[string:"""]' Is there a 'special' SecureCRT escape character or something? Code:
Language="VBScript" Interface="1.0" Sub Main() Dim objTab Dim szStartString, szEndingString, szResult Dim sversion, simage_file crt.Screen.Synchronous = True szStartString = "#" szEndingString = "#" Set objTab = crt.GetScriptTab If Not objTab.session.connected then MsgBox "Not Connected. Please connect before running this script." exit sub end if crt.Screen.Send "show version | include Cisco IOS Software|flash:/" crt.Screen.Send chr(13) szResult = objTab.Screen.ReadString(szEndingString) Dim n_string_start, n_string_end n_string_start = instr(1,szResult, "Version")+8 n_string_end = instr(n_string_start, szResult, ", ") sverion = mid(szResult, n_string_start, n_string_end - n_string_start) n_string_start = instrrev(1, szResult, Cstr(chr(34)))+1 msgbox n_string_start 'n_string_end = instrrev(1, szResult, ) simage_file = mid(szResult, n_string_start, n_string_end - n_string_start) msgbox simage_file 'crt.Session.Disconnect End sub ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
#2
|
|||
|
|||
Hi gunslingor,
The question you are asking is really a VBScript question. I would suggest taking a look at Microsoft's documentation on VBScript. Here is the MSDN location as of the date of this post (Microsoft could change the location in the future): http://msdn.microsoft.com/en-us/libr...(v=vs.84).aspxTo answer your question, the issue is likely one of incorrect VBScript syntax. Your use of InStrRev() appears to be searching the number one (1) for a string with the begin point of a quote ("). Here is the syntax from MSDN: InStrRev(string1, string2[, start[, compare]])My guess is that you need to modify the order to be the following: InStrRev(szResult, chr(34), 1)This code will only search the first character of the string, so I am not sure what your goal is. Perhaps if you can post an example of the data you want to parse, and what you want to capture, we can point you in a better direction. Additionally, if you want to perform complex parsing of data, you may want to turn to regular expressions. Chapter 4.3 of the scripting manual covers various strategies for parsing data. Last edited by rtb; 05-15-2013 at 01:53 PM. |
#3
|
|||
|
|||
Quote:
![]() The code you suggested, i believe, would actually search the entire string since the "1" just defines the starting position starting from the end... according to documentation, the end position is actually -1 and this is the default, so I actually just took it out completely. Regarding the use of regular expressions, yeah I think I will end up using it for IP/MAC addresses and potentially others, but interfaces names, OS, and other field data might be to variable for this. Thanks for the chapter reference, I'll read it... the manual is quite good I must say. I noticed this before on VB reference sites, and you referenced it again in your last post. "InStrRev(string1, string2[, start[, compare]])".... Waits with all the odd brackets, bad HTML interpretation (e.g. http://www.w3schools.com/vbscript/func_instr.asp)? For thread completeness sake, here's the wrap up-This code runs a one command, pulls out the OS version and the image file name from the output, and displays the results in a textbox. Once I get all these tidbits of data assigned to variables, I'll output them to a text file. Code:
Language="VBScript" Interface="1.0" Sub Main() Dim objTab Dim szStartString, szEndingString, szResult Dim sversion, simage_file crt.Screen.Synchronous = True szStartString = "#" szEndingString = "#" Set objTab = crt.GetScriptTab If Not objTab.session.connected then MsgBox "Not Connected. Please connect before running this script." exit sub end if crt.Screen.Send "show version | include Cisco IOS Software|flash:/" crt.Screen.Send chr(13) szResult = objTab.Screen.ReadString(szEndingString) 'pull out the OS version Dim n_string_start, n_string_end n_string_start = instr(1,szResult, "Version")+8 n_string_end = instr(n_string_start, szResult, ", ") sverion = mid(szResult, n_string_start, n_string_end - n_string_start) 'pull out the image file name n_string_start = instrrev(szResult, chr(47))+1 n_string_end = instrrev(szResult, chr(34)) simage_file = mid(szResult, n_string_start, n_string_end - n_string_start) 'test display for results msgbox (sverion & chr(13) & simage_file) 'crt.Session.Disconnect End sub |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|