Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-06-2015, 02:41 PM
mcox mcox is offline
Registered User
 
Join Date: Jul 2015
Posts: 6
setting default directory, and slowing "Send" function

I have a Python script that, among other things, asks the user to select a file then sends that file to the host (below). I have two questions.

First, can I set a starting path when the dialog opens? As it is, the user has to navigate to the directory each time. This is going to be repeated often, so it'd be nice for the dialog to just open already in the correct folder.

Second, can I slow down the Send function? It goes too fast causing errors, and the line and character delay settings for the session apparently don't apply when sending text this way - only if I copy and paste. Thanks.

Code:
	filePath = crt.Dialog.FileOpenDialog(title="Please select a text file", filter="Text Files (*.txt)|*.txt||")
	for line in open(filePath, "r"):
		crt.Screen.Send(line)
Using Mac version 7.3.0.
Reply With Quote
  #2  
Old 07-06-2015, 03:28 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi mcox,

From the SecureCRT help topic Scripting / Script Objects Reference / Dialog Object / FileOpenDialog (in part):

Quote:
Remarks
If the defaultFilename parameter is simply a filename (no path provided), the file dialog browser will open in current working directory. If the defaultFilename parameter specifies an absolute path to a file, the file dialog browser will open in the parent directory of the file.

Python Syntax

crt.Dialog.FileOpenDialog([title, [buttonLabel, [defaultFilename, [filter ]]]])
Does that help you accomplish your goal?


For #2, see this example script. It illustrates the most efficient way to send data to devices that can be overwhelmed by receiving too much data.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 07-06-2015, 05:13 PM
mcox mcox is offline
Registered User
 
Join Date: Jul 2015
Posts: 6
Quote:
Does that help you accomplish your goal?
I can get it to look at a volume, but not a subdirectory, i.e. /Volumes/SANDISK32 works but not /Volumes/SANDISK32/subdir or /Volumes/SANDISK32/subdir/. Those just point to the /Volumes/SANDISK32 location.

Quote:
For #2, see this example script. It illustrates the most efficient way to send data to devices that can be overwhelmed by receiving too much data.
I tried adapting to my use of selecting an input file rather than the clipboard. It's actually waiting 3 seconds between each line, so I suppose it isn't seeing the line echoed back. I dropped it to 1 and it works, but even 1 second is really slow and it doesn't appear that less than a second can be used.

Code:
	for line in open(filePath, "r"):
		crt.Screen.Send(line)
		bSuccess = False
		if not line == "":
			bSuccess = crt.Screen.WaitForString(line,1)
        else:
        	crt.Session.SetStatusText("Sent a blank line; waiting for cursor to move...")
        	bSuccess = crt.Screen.WaitForCursor(3)
        	crt.Session.SetStatusText("")
        if not bSuccess:
         crt.Dialog.MessageBox("Abandoning config load operation.")
         return
Reply With Quote
  #4  
Old 07-07-2015, 02:11 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi mcox,

Please post the new code but mask anything sensitive.

If you are not pointing to a particular *file*, the way I interpret the Help file information is it is going to use the parent directory, so it sounds to me like subdir is being interpreted as the file and so it is opening to the parent (SANDISK32) directory.


Regarding #2, I am not sure I understand.

Quote:
It's actually waiting 3 seconds between each line, so I suppose it isn't seeing the line echoed back.
Is the 3 second delay you are referring to from the WaitForCursor()?

Code:
        	bSuccess = crt.Screen.WaitForCursor(3)
Or are you saying you did have the timeout for WaitForString() configured for 3 seconds and changed it to 1?

Code:
			bSuccess = crt.Screen.WaitForString(line,1)

I have added this thread to a feature request in our product enhancement database for the ability to wait for milliseconds in crt.Screen.WaitForCursor and WaitForString. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, contact support@vandyke.com and include "Feature Request - Forum Thread #12026" in the subject line.
__________________
Thanks,
--Brenda

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

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 07:33 PM.