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 05-05-2016, 08:28 AM
praneethkumar90 praneethkumar90 is offline
Registered User
 
Join Date: May 2016
Posts: 1
SecureCRT: VBscript. Printing the variable into console

Hi, We have written a VB program to access secureCrt shell and execute the command in the jump server.

I am running the code from local windows machine using command "C:\Users\abc\Desktop\secureCRT\Test>securecrt.exe /SCRIPT "C:\Users\abc\Desktop\secureCRT\Test\oswatch_drv.vbs" /ARG "ls -l" /S "ghfet.intl.xyz.com"

Below is the code:

#$language = "VBScript"
#$interface = "1.0"
Set objTab = crt.GetScriptTab
Set g_shell = CreateObject("WScript.Shell")

Public szData

crt.Sleep 6000

objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True

Dim szCommand, szPrompt, nRow, szLogFileName, nIndex

Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False

nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)

crt.Screen.Synchronous = True

Dim pran

Sub Main

strVal = crt.Arguments(0)

crt.Screen.Send "pwd" & chr(13)
crt.Screen.WaitForString "[xyz@xlpv0002 ~]$"
crt.Screen.Send "sh test.sh" & chr(9) & chr(13)

szData = CaptureOutputOfCommand("sh test.sh", "[xyz@xlpv0002 ~]") & vbCr
'MsgBox(szData)
pran = szData

crt.Clipboard.Format = "CF_TEXT"
crt.Clipboard.Text = pran

crt.Dialog.MessageBox("Text is now in the clipboard: \n\n" + crt.Clipboard.Text)
'MessageBox.Show(szData)

If Not SendExpect("exit", "[xyz@xlpv0002 ~]") then exit sub

g_shell.Run "%comspec% /c taskkill /IM SecureCRT.exe /F"

End Sub

'=======================================================================
Function CaptureOutputOfCommand(szCommand, szPrompt)
if crt.Session.Connected <> True then
CaptureOutputOfCommand = "[ERROR: Not Connected.]"
exit function
end if

objTab.Screen.Send szCommand & vbcr
objTab.Screen.WaitForString vbcr
CaptureOutputOfCommand = objTab.Screen.ReadString(szPrompt)

End Function
'======================================================================
Function SendExpect(szSend, szExpect)
if objTab.Session.Connected <> True then exit function

objTab.Screen.Send szSend & vbcr
objTab.Screen.WaitForString szExpect

SendExpect = True
End Function
'========================================


I am running the script present in the jump server and able to capture the script output into "MSG Box" but, i want the output to be redirected into windows console.

Is there any way to print the variable szData into console?
Reply With Quote
  #2  
Old 05-05-2016, 10:58 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,015
Hi praneethkumar90,

Quote:
I am running the script present in the jump server and able to capture the script output into "MSG Box" but, i want the output to be redirected into windows console.

Is there any way to print the variable szData into console?
What do you mean by "windows console"?

Do you want the output to display in the SecureCRT terminal window?

What version of SecureCRT are you using?

If you want to capture the output to a file, you could just configure logging in the session (Terminal / Log File category of Session Options).

What problem are you trying to solve?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
secure crt , vbscript


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 02:58 PM.