0

I am trying to write a TCL/TK Script that accesses an INI File with the command [::ini::open DBW.ini]. I am using the inifile package for this and am trying to run on wish for the gui. However, wish answers with "couldn't open "DBW.ini": no such file or directory". The odd thing about this is, that I can run this Code in the VSCode extension "Code Runner". Code Runner is configured to access the same wish Compiler that I'm trying to run on my Windows System.

Why would I be able to run this Code through VSCode, but when im using the wish Compiler directly it throws an error message.

Thank you in advance

Wheak
  • 3
  • 1

1 Answers1

0

Most likely your Tcl code is not being executed in the same directory as where the DBW.ini file is. The Tcl command pwd will return the directory where the code is executing. If this is not where the ini file is, a simple fix would be to specify the whole path to the file when you try to open it, something like:

[::ini::open C:/some/where/DBW.ini]
Colin Macleod
  • 4,222
  • 18
  • 21
  • You were right, when I put out the current path with `pwd` it was a different one from when i started it with VSCode, however, i need to make this script portable as it will be used on multiple Servers and i'd want to keep it generic. Is there any way to make wish change into the directory where the file is? – Wheak Mar 04 '22 at 10:46
  • Well you could pass the directory as an argument to the script. Or is there some way the script could find this info for itself, e.g. is there an environment variable that would tell you the directory to look in? – Colin Macleod Mar 04 '22 at 11:15
  • I used `[info script]` which returns the path of the script that is used ad saved it into a Variable. Then i trimmed off the filename with `trimright` and assembled the path with the INI file name. This worked. Thank you xou've been a great help. – Wheak Mar 04 '22 at 11:46
  • 1
    Glad to be of assistance. Note that trimming off the filename can be done with `file dirname` - https://www.tcl-lang.org/man/tcl8.6/TclCmd/file.htm#M13 – Colin Macleod Mar 04 '22 at 13:06
  • 1
    The _canonical_ way to get the location of the script is `file dirname [file normalize [info script]]`. Often you save this with `variable scriptDirectory [file dirname [file normalize [info script]]]` (with the variable name being whatever's convenient). – Donal Fellows Mar 04 '22 at 15:31