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 03-31-2021, 11:32 AM
Chris_T Chris_T is offline
Registered User
 
Join Date: Mar 2021
Posts: 3
Phyton scripts after upgrade

Hi Gents,

We have upgraded SecureCRT from Version 8 to Version 9.0.1

For long we have been using Python scripts and never had issues. With the new version all the scripts seem to not work anymore and and seem to fail to address files and folders (see below, simply opening file object within the local script folder not working anymore):

----------------------------------------------------------
IOError

Error:
File: C:\Users\...\script.py
Line:14

f = open(file1,'w')
---------------------------------------------------------


Not a python geek though, but is there a workaround to address this? Updating all scripts will be a pain..

Many thanks, Chris
Reply With Quote
  #2  
Old 03-31-2021, 02:47 PM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 132
Hi Chris,

There are a lot of variables that come into play with regards to scripting issues. In this particular case, we're going to need some more information about your setup in order to troubleshoot further. Could you please answer the following questions?
  • Which version of Windows are you on?
  • What is the exact version of SecureCRT from which you upgraded to version 9.0.1?
  • Is this upgrade something that happened in-place from the older version of SecureCRT to the newer version on the same machine, or did you move to another machine in the process of upgrading SecureCRT?
  • What is the encoding of the file your script is attempting to load? (ANSI, UTF-8, UTF-8 with BOM, etc.)
  • What exactly does the "file1" variable value reflect? A file name alone? A full path to a file?
--Cameron
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-06-2021, 04:18 AM
Chris_T Chris_T is offline
Registered User
 
Join Date: Mar 2021
Posts: 3
Hi Cameron, thanks for checking.

I have upgraded from SecureCRT version 8.3 on my Windows 10 PC, which is still the same as before.
With the old version we were able to open files from the local folder we started the .py file from, see below:

Code:
    outputfile = str(date.today())
    file1 = ("Inventory-" + outputfile + ".csv")
    f=open(file1,'w')
This now is not possible anymore. I have to exactly specify the path where to open the file:

Code:
localfolder = r'C:\\Users\..\\..\\..\\'
    
    outputfile = str(date.today())
    file1 = (localfolder + "Inventory-" + outputfile + ".csv")
    f=open(file1,'w')
This is not very convenient, as the folder might change from time to time. And for now I am not sure how to let python find the local folder by itself., this i have to investigate.

Regards, Chris

Last edited by cboyack; 04-06-2021 at 07:19 AM. Reason: Please use [CODE] and [/CODE] tags to denote areas of code
Reply With Quote
  #4  
Old 04-06-2021, 01:30 PM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 132
Hi again Chris,

In all honesty, it seems like a miracle that the scripts worked as nicely as they did for you with the older version of SecureCRT, as the current working directory can mean a lot of different things, and it just happened to land nicely for you in the past. Take the following script, for example:
Code:
# $language = "Python"
# $interface = "1.0"

import os
strDir1 = os.getcwd()
strDir2 = os.path.dirname(os.path.realpath("."))
strDir3 = os.path.dirname(os.path.realpath(__file__))
strDir4 = os.path.dirname(crt.ScriptFullName)
crt.Dialog.MessageBox("dir1: {}\ndir2: {}\ndir3: {}\ndir4: {}".format(
    strDir1,
    strDir2,
    strDir3,
    strDir4))
If you run this script, you can see how, depending on the context, different versions of the current working directory can result in a file being written/opened in wildly different locations. If you're simply looking to have the file be written within the same directory in which the .py file was run, please consider using the format from line 7 or 8 from the above script to obtain that directory for further use in your script.

If you're looking for some other behavior in which the script will open/write to a file in some other location, what's the anchor for that location?
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-07-2021, 01:47 AM
Chris_T Chris_T is offline
Registered User
 
Join Date: Mar 2021
Posts: 3
Hi Cameron,

our scripts were doing the job, so there never was a reason to think about or to change the way files were addressed. Anyway, with your input on this it seems to be the best to do an overhaul on them.

Many thanks for your efforts!!
Reply With Quote
  #6  
Old 04-07-2021, 08:13 AM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 132
Hi Chris,

Happy to help.

I'm sorry it's not a simple point and click fix, but I agree with you that making the change to point to the proper relative directory is a good thing to do now - to protect you against similar issues cropping up in the future with any other potential SecureCRT version upgrades
__________________
Thanks,
--Cameron

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:23 AM.