Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Odd problem running a downloaded Tcl script.

69 views
Skip to first unread message

Richard Owlett

unread,
Mar 22, 2019, 10:19:41 AM3/22/19
to
I am using Tcl/Tk 8.6 on a Debian Stretch system wit the MATE desktop
environment.

I have downloaded a Tcl script , marked it as executable, placing it
several levels below /home.

If I use Caja to browse to that sub-directory and then double-click
either "Run in terminal" or "Run", it executes as expected.

HOWEVER, execution fails if run by:
1. Opening a MATE Terminal window.
Attempting to run by entering either
"/home/richard/apath/test.tcl"
or
"tclsh /home/richard/apath/test.tcl"
2. Creating a MATE Launcher with either of the above strings entered
in the Command box.


What is the difference in "execution environment" between what works
and what doesn't?
The symptom is that it can not find a existing data file, suggesting
a "path" related issue.

I wish to use a MATE Launcher.
Modifying the script is *NOT* feasible.
Suggestions?
TIA


Harald Oehlmann

unread,
Mar 22, 2019, 10:43:38 AM3/22/19
to
I suppose, showing the first line of the script may shed some light.
May you share just the first line in the script file ?
There might be a shebang (#!...).

Thank you,
Harald

Richard Owlett

unread,
Mar 22, 2019, 11:17:04 AM3/22/19
to
You proved I know even less about Tcl than I thought ;{
The first three lines are
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

Actually the script is nut.tcl from NUTsqlite
[http://nut.sourceforge.net/].

What should I have read?

Thanks.




Andreas Leitgeb

unread,
Mar 22, 2019, 11:35:05 AM3/22/19
to
Richard Owlett <row...@cloud85.net> wrote:
> On 03/22/2019 09:43 AM, Harald Oehlmann wrote:
>> Am 22.03.2019 um 15:19 schrieb Richard Owlett:
>>> I have downloaded a Tcl script , marked it as executable, placing it
in /home/richard/apath/test.tcl apparently ;-) But that's fine.

>>> What is the difference in "execution environment" between what works
>>> and what doesn't?
>>> The symptom is that it can not find a existing data file, suggesting
>>> a "path" related issue.

Next question would be, where the data file resides (I assume it does
exist, or it wouldn't work from caya, either)

By what path (relative or absolute) the file is accessed in what way?
e.g. is it passed to [source], used via [package require ...], or with
a plain old [open ...]

A likely difference between "run in terminal" and "opening a terminal
and running it there" is, that the opened terminal might be a login
shell, whereas "run in terminal" almost never involves a login-shell.
How this difference causes different behaviour will require more
information to diagnose.

Harald Oehlmann

unread,
Mar 22, 2019, 11:51:56 AM3/22/19
to
Then try the seen lines manually in a shell:
"exec tclsh"
and see what happens.

If it does not work (no tclsh in path), a symbolic link etc may
eventually help...

I don't know your environment nor the words Mate or Caja (well, the
first is probably English for Friend, the 2nd probably Spanish for
"Bank", but that is not the question ;-) )

Harald

Robert Heller

unread,
Mar 22, 2019, 1:33:51 PM3/22/19
to
At Fri, 22 Mar 2019 09:19:33 -0500 Richard Owlett <row...@cloud85.net> wrote:

>
> I am using Tcl/Tk 8.6 on a Debian Stretch system wit the MATE desktop
> environment.
>
> I have downloaded a Tcl script , marked it as executable, placing it
> several levels below /home.
>
> If I use Caja to browse to that sub-directory and then double-click
> either "Run in terminal" or "Run", it executes as expected.
>
> HOWEVER, execution fails if run by:
> 1. Opening a MATE Terminal window.
> Attempting to run by entering either
> "/home/richard/apath/test.tcl"
> or
> "tclsh /home/richard/apath/test.tcl"
> 2. Creating a MATE Launcher with either of the above strings entered
> in the Command box.
>
>
> What is the difference in "execution environment" between what works
> and what doesn't?
> The symptom is that it can not find a existing data file, suggesting
> a "path" related issue.

It could be one of several things, including what the "Current Working
Directory" is. (I know, most Desktop environments don't set the "Current
Working Directory" or, generally, don't even believe in such a thing, since in
a GUI desktop there is, conceptually, no such thing.)

Did the Tcl script come with data files? Are they in the same place as the
Tcl script? Does the Tcl script expect them to be there or someplace else?

>
> I wish to use a MATE Launcher.
> Modifying the script is *NOT* feasible.
> Suggestions?

OK, here is a totally off-the-wall suggestion:

fire up a terminal window (eg from the Mate system menu) and at the shell
prompt and type:

/home/richard/apath/test.tcl

(assuming this is the proper path to the script.)

What output is there in the terminal window?

> TIA
>
>
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Robert Heller

unread,
Mar 22, 2019, 2:12:37 PM3/22/19
to
Actually neigher. MATE is a Desktop environment (forked from Gnome2) and Caja
is a GUI file manager.

>
> Harald

Robert Heller

unread,
Mar 22, 2019, 2:12:38 PM3/22/19
to
At Fri, 22 Mar 2019 10:16:56 -0500 Richard Owlett <row...@cloud85.net> wrote:

>
> On 03/22/2019 09:43 AM, Harald Oehlmann wrote:
> > Am 22.03.2019 um 15:19 schrieb Richard Owlett:
> >> I am using Tcl/Tk 8.6 on a Debian Stretch system wit the MATE desktop
> >> environment.
> >>
> >> I have downloaded a Tcl script , marked it as executable, placing it
> >> several levels below /home.
> >>
> >> If I use Caja to browse to that sub-directory and then double-click
> >> either "Run in terminal" or "Run", it executes as expected.
> >>
> >> HOWEVER, execution fails if run by:
> >> 1. Opening a MATE Terminal window.
> >> =C2=A0=C2=A0 Attempting to run by entering either
> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "/home/richard/apath/test.tcl"
> >> =C2=A0=C2=A0 or
> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "tclsh /home/richard/apath/test.tcl"
> >> 2. Creating a MATE Launcher with either of the above strings entered
> >> =C2=A0=C2=A0 in the Command box.
> >>
> >>
> >> What is the difference in "execution environment" between what works
> >> and what doesn't?
> >> The symptom is that it can not find a existing data file, suggesting
> >> a "path" related issue.
> >>
> >> I wish to use a MATE Launcher.
> >> Modifying the script is *NOT* feasible.
> >> Suggestions?
> >> TIA
> >>
> >>
> >=20
> > I suppose, showing the first line of the script may shed some light.
> > May you share just the first line in the script file ?
> > There might be a shebang (#!...).
> >=20
> > Thank you,
> > Harald
> >=20
>
> You proved I know even less about Tcl than I thought ;{
> The first three lines are
> #!/bin/sh
> # the next line restarts using tclsh \
> exec tclsh "$0" "$@"
>
> Actually the script is nut.tcl from NUTsqlite
> [http://nut.sourceforge.net/].
>
> What should I have read?

Replace the first three lines with this one line:

#!/usr/bin/tclsh

(assuming tclsh is in fact in /usr/bin, if it is somewhere else, you need to
put that in).

*Alternitively* did you try to put in the exact and *complete* absolute path
to tclsh in the Launcher command line (not just "tclsh", but the *full* abs.
path, starting with "/").

The "hack" they are using is meant for people from from the command line who
might have tclsh installed someplace odd, but who have arranged for their
pathlist ($PATH) to include that location. Running from a Desktop launcher is
probably not going to have the $PATH variable set up properly (if set up at
all) for that sort thing (not unless you are really, really clever about
setting up your desktop), so you need the script to have the proper location
"hard wired" into the script in order for it to work.

>
> Thanks.

Christian Gollwitzer

unread,
Mar 22, 2019, 2:23:10 PM3/22/19
to
Am 22.03.19 um 16:19 schrieb Richard Owlett:
> I have downloaded a Tcl script , marked it as executable, placing it
> several levels below /home.
>
> If I use Caja to browse to that sub-directory and then double-click
> either "Run in terminal" or "Run", it executes as expected.
>
> HOWEVER, execution fails if run by:
> 1. Opening a MATE Terminal window.
>    Attempting to run by entering either
>       "/home/richard/apath/test.tcl"

> Suggestions?

Try:

cd /home/richard/apath/
./test.tcl


Christian

PS: Beware how to pronounce that filename ;)

Richard Owlett

unread,
Mar 22, 2019, 4:31:15 PM3/22/19
to
*GIVE THAT MAN A CIGAR!*

"/home/richard/apath/test.tcl" FAILS

"
cd/home/richard/apath/
./test.tcl
"
WORKS a charm!

To achieve my goal of using a MATE Launcher all that's needed is a batch
file with those two lines.

THANKS ALL

P.S. I'll be more careful with dummy file names in future ;/


heinrichmartin

unread,
Mar 24, 2019, 6:27:02 PM3/24/19
to
On Friday, March 22, 2019 at 9:31:15 PM UTC+1, Richard Owlett wrote:
> To achieve my goal of using a MATE Launcher all that's needed is a batch
> file with those two lines.

As someone who prefers solutions over workarounds, I looked up "mate launcher working directory" and found https://askubuntu.com/a/1042782. Basically, it says that you cannot set it in the GUI, but in the .desktop file.

https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.2.html#key-path

Robert Heller

unread,
Mar 24, 2019, 8:01:56 PM3/24/19
to
At Sun, 24 Mar 2019 15:26:59 -0700 (PDT) heinrichmartin <martin....@frequentis.com> wrote:

>
> On Friday, March 22, 2019 at 9:31:15 PM UTC+1, Richard Owlett wrote:
> > To achieve my goal of using a MATE Launcher all that's needed is a batch
> > file with those two lines.
>
> As someone who prefers solutions over workarounds, I looked up "mate
> launcher working directory" and found https://askubuntu.com/a/1042782.
> Basically, it says that you cannot set it in the GUI, but in the .desktop
> file.

Right. Desktop environments don't really support the idea of a "current
working directory". There basically is no conceptual equivalent of the CLI
command "cd". The file manager has its idea of what a given file list window
is displaying, but since the file manager is not really anything like a CLI
shell, that info is pretty much "private" to the file manager, since the file
manager might have any number of windows open, each displaying a different
"folder" (silly terminolgy). And the Desktop manager's Launcher or Menu is
not bound to a directory or folder at all. At best it will inherit from the
shell that launched the Desktop (maybe a login shell sitting at $HOME) or
maybe be set in some dot config file (eg .desktop). But that is going to be
pretty much useless.

Scripts like the OP is using should not really depend on the CWD. Instead (in
the case of Tcl, it should be doing something like:

set scriptdir [file dirname [info script]]
set datafilePath [file join $scriptdir mydatafile.txt]

If it wants to access datafiles that ship with the script.

>
> https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.2.html#key-path

Richard Owlett

unread,
Mar 25, 2019, 6:55:36 AM3/25/19
to
Thank you. I'll have to do a closer read of that material and internal
links. Even my brief read hints at solutions to peripheral issues.


Richard Owlett

unread,
Mar 25, 2019, 7:05:41 AM3/25/19
to
On 03/24/2019 07:01 PM, Robert Heller wrote:
> At Sun, 24 Mar 2019 15:26:59 -0700 (PDT) heinrichmartin <martin....@frequentis.com> wrote:
>
>>
>> On Friday, March 22, 2019 at 9:31:15 PM UTC+1, Richard Owlett wrote:
>>> To achieve my goal of using a MATE Launcher all that's needed is a batch
>>> file with those two lines.
>>
>> As someone who prefers solutions over workarounds, I looked up "mate
>> launcher working directory" and found https://askubuntu.com/a/1042782.
>> Basically, it says that you cannot set it in the GUI, but in the .desktop
>> file.
>
> Right. Desktop environments don't really support the idea of a "current
> working directory". There basically is no conceptual equivalent of the CLI
> command "cd". The file manager has its idea of what a given file list window
> is displaying, but since the file manager is not really anything like a CLI
> shell, that info is pretty much "private" to the file manager, since the file
> manager might have any number of windows open, each displaying a different
> "folder" (silly terminolgy). And the Desktop manager's Launcher or Menu is
> not bound to a directory or folder at all. At best it will inherit from the
> shell that launched the Desktop (maybe a login shell sitting at $HOME) or
> maybe be set in some dot config file (eg .desktop). But that is going to be
> pretty much useless.
>
> Scripts like the OP is using should not really depend on the CWD. Instead (in
> the case of Tcl, it should be doing something like:
>
> set scriptdir [file dirname [info script]]
> set datafilePath [file join $scriptdir mydatafile.txt]

I do not understand those two lines.
Suspect I'm missing something basic.
Reading assignment please. [ retirement == reading time available ;]
Thank you.

heinrichmartin

unread,
Mar 25, 2019, 8:13:45 AM3/25/19
to
First question: should the script rely on the working directory or should it pick the resource relative to itself? Robert suggested the latter.

> set scriptdir [file dirname [info script]]

Get the location of self. I usually use a similar pattern in bash:

HERE=`dirname $(readlink -e $0)`

Note that the Tcl version above fails when the script is invoked via a link.

> set datafilePath [file join $scriptdir mydatafile.txt]

Find the resource relative to self. You might want to look and various pkgIndex.tcl files or documentation of [package] for similar patterns (although the package system already provides the path as $dir).

BTW, you do not even need a(nother) wrapper script ... you could just `cd $HERE && ...` in the existing script.

Robert Heller

unread,
Mar 25, 2019, 9:47:49 AM3/25/19
to
At Mon, 25 Mar 2019 05:13:42 -0700 (PDT) heinrichmartin <martin....@frequentis.com> wrote:

>
> On Monday, March 25, 2019 at 12:05:41 PM UTC+1, Richard Owlett wrote:
> > On 03/24/2019 07:01 PM, Robert Heller wrote:
> > > Scripts like the OP is using should not really depend on the CWD. Instead (in
> > > the case of Tcl, it should be doing something like:
> > >
> > > set scriptdir [file dirname [info script]]
> > > set datafilePath [file join $scriptdir mydatafile.txt]
> >
> > I do not understand those two lines.
> > Suspect I'm missing something basic.
> > Reading assignment please. [ retirement == reading time available ;]
> > Thank you.
>
> First question: should the script rely on the working directory or should it pick the resource relative to itself? Robert suggested the latter.
>
> > set scriptdir [file dirname [info script]]
>
> Get the location of self. I usually use a similar pattern in bash:
>
> HERE=`dirname $(readlink -e $0)`
>
> Note that the Tcl version above fails when the script is invoked via a link.

Advanced users can always use [file readlink ...] and/or [file normalize ...]

>
> > set datafilePath [file join $scriptdir mydatafile.txt]
>
> Find the resource relative to self. You might want to look and various pkgIndex.tcl files or documentation of [package] for similar patterns (although the package system already provides the path as $dir).
>
> BTW, you do not even need a(nother) wrapper script ... you could just `cd $HERE && ...` in the existing script.
>

0 new messages