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-06-2018, 12:32 PM
Hang Hang is offline
Registered User
 
Join Date: Jul 2016
Posts: 21
Post Logging output

Hi,

I am having problem capturing the last command when logging a session. I just want to understand why it is not working the way it supposed to.

If I run the following code:

Code:
def main():	
	prompt = "A#"
	currentTab = crt.GetScriptTab()
	currentTab.Screen.Synchronous = True
	currentTab.Session.Log(True)	
	currentTab.Screen.Send("\rthis is line 1 \r")
	currentTab.Screen.WaitForString(prompt)	
	currentTab.Screen.Send("this is line 2\r")
	currentTab.Screen.WaitForString(prompt)	
	currentTab.Screen.Send("this is line 3 \r")	
	currentTab.Screen.WaitForString(prompt)	
	#currentTab.Screen.Send("$")
	#currentTab.Screen.WaitForString("$")
	currentTab.Session.Log(False)
	
main()
I get this output:

Quote:
A#
A# this is line 1
^
Error: Bad command.
A# this is line 2
^
Error: Bad command.
As you can see "this is line 3" is missing. However if I run the following code.

Code:
def main():	
	prompt = "A#"
	currentTab = crt.GetScriptTab()
	currentTab.Screen.Synchronous = True
	currentTab.Session.Log(True)	
	currentTab.Screen.Send("\rthis is line 1 \r")
	currentTab.Screen.WaitForString(prompt)	
	currentTab.Screen.Send("this is line 2\r")
	currentTab.Screen.WaitForString(prompt)	
	currentTab.Screen.Send("this is line 3 \r")	
	currentTab.Screen.WaitForString(prompt)	
	currentTab.Screen.Send("$")
	currentTab.Screen.WaitForString("$")
	currentTab.Session.Log(False)
	
main()
I will get the following output:

Quote:
A#
A# this is line 1
^
Error: Bad command.
A# this is line 2
^
Error: Bad command.
A# this is line 3
^
Error: Bad command.
By adding a send and waitfor "$", I get all the lines. Why is that? Is there a better way of logging everything without adding some random waitfor at the end of my code, just so I can capture all outputs?

Thanks,
Reply With Quote
  #2  
Old 02-06-2018, 01:06 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,295
Hi Hang,

What version of SecureCRT are you using?

On what specific OS?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 02-06-2018, 01:14 PM
Hang Hang is offline
Registered User
 
Join Date: Jul 2016
Posts: 21
I am using 8.1.4 (32 bit version) on Win7 Pro 64 bit
Reply With Quote
  #4  
Old 02-06-2018, 02:11 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,295
Hi Hang,

Thanks for the info.

An eagle-eyed colleague spotted this in your first Send():

Code:
currentTab.Screen.Send("\rthis is line 1 \r")
This immediately puts you out of synch and "one line behind" in your script.

To stay in synch, call WaitForString(prompt) for *every* \r that you Send().

See attached illustration:

Attached Images
File Type: png StayInSynch.png (119.6 KB, 508 views)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 02-07-2018, 11:39 AM
Hang Hang is offline
Registered User
 
Join Date: Jul 2016
Posts: 21
Thanks Brenda,

That works! So does it apply to "\n" as well? I need a waitfor after every "\n"?
Reply With Quote
  #6  
Old 02-07-2018, 11:51 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,295
Hi Hang,

The \r (carriage return) is what correlates to pressing Enter on the keyboard. You should not be Send()-ing \n (new line) characters.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
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 01:52 PM.