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 02-11-2007, 12:43 PM
puyo puyo is offline
Registered User
 
Join Date: Aug 2006
Posts: 8
store output screen in array ?

HI

i hope some one can help me

i want store the output from the screen each line in a array, i need first send

crt.Screen.Send " ls -1"




any suggestion ?

Last edited by puyo; 02-11-2007 at 12:45 PM.
Reply With Quote
  #2  
Old 02-12-2007, 04:00 AM
puyo puyo is offline
Registered User
 
Join Date: Aug 2006
Posts: 8
i find a way but im not verry happy about


#$language = "VBScript"
#$interface = "1.0"


Sub Main

Dim fso, File, sText, i

dim tab(255)

Const ForReading = 1


CRT.Session.logFileName = "C:\log.txt"
CRT.Session.Log(True)
crt.Screen.Send "ls -1" & VbCr
crt.Screen.WaitForString "#"
CRT.Session.Log(False)


Set fso = CreateObject("Scripting.FileSystemObject")
set File = fso.OpenTextFile("C:\log.txt", ForReading, false)

Do while not File.AtEndOfStream
sText = File.ReadLine()
tab(i) = sText
i = i + 1

Loop
File.Close


Set File = nothing
Set fso = nothing



for z=1 to i -1

msgbox tab(z)

next


End Sub


Reply With Quote
  #3  
Old 02-13-2007, 07:03 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hi Puyo,

I see that you're opening a text file and working with tabs, but I'd like to get a better understanding of your overall goal.

Can you tell us a little more about what you're wanting to do?

Are you wanting to capture data from the screen, put it into an array?

After the data is in the array, what do you want to do?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #4  
Old 02-15-2007, 06:10 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Puyo,

It sounds your main goal is to read output from a command into an array. Below is an example script which sends "ls -1" and reads the data from the command into an array. Data is collected using Crt.Screen.ReadString(). At the end of the script the lines that were read into the array are displayed in a message box.

Does this help?

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

crt.screen.synchronous = TRUE

Dim szOutput, szFinishedOutput, szCommand, szPrompt, nResult

Dim szStringArray

nIndex = 1
szOutput = ""
szCommand = "ls -1"
szPrompt = " $"

crt.screen.send szCommand & vbcr
nResult = crt.screen.waitforstrings(vbcr, vblf, 5)
szOutput = szOutput & crt.screen.readstring()

do
    szOutput = szOutput & crt.screen.readstring()
    if InStr(1, szOutput, szPrompt, 1) > 0 then exit do
loop

szStringArray = Split(szOutput, vbcr, -1, 1)

msgbox "Finished running command and collecting data..." & vbcr & _
        szOutput
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]

Last edited by miked; 02-15-2007 at 06:55 PM.
Reply With Quote
  #5  
Old 02-17-2007, 01:18 PM
puyo puyo is offline
Registered User
 
Join Date: Aug 2006
Posts: 8
yes im wanting to capture data from the screen, put it into an array

I didn't hope for any suggestion

miked thanks for the simple i will try


Last edited by puyo; 02-17-2007 at 01:21 PM.
Reply With Quote
  #6  
Old 02-19-2007, 11:21 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
ReadString example

You're welcome. In my testing, ReadString combined with InStr was a little slower than equivalent scripts which use Get or Get2 combined with WaitForStrings. If you have a lot of data in the SecureCRT screen, you might want to consider Get or Get2 instead.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply


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 08:40 PM.