Newbie Question: This May Sound Dumb...

0 views
Skip to first unread message

Jason Mowat

unread,
May 26, 1999, 3:00:00 AM5/26/99
to
Hi all,

I have Tcl8.0 for Windows. I am running Windows98. I would like to create
a Tcl script that does the following:

echo "Hello world!"

I would like to be able to double click this Hello.tcl file and have a
command prompt show me:

Hello world!

When I try it now, the first thing that happens is that wish tries to
execute it. wish complains about echo not being a recognized command. I
changed the echo to a puts, and now all wish does is shows me a grey window.
When I go into my Tclsh, and I get the % prompt, I can type `echo "Hello
world!"` and it behaves normally. However, when I put the command into a
file (Hello.tcl) and try to execute it from the prompt, I get an error that
Hello.tcl does not exist.

What do I need to do to run programs without using Tk (just Tcl)?

Thanks!
Jason

P.S. If you could also include an email response to jmo...@ibm.net for any
posted replies, it would be appreciated!

Scott Redman

unread,
May 26, 1999, 3:00:00 AM5/26/99
to jmo...@ibm.net

Jason Mowat wrote:
>
> Hi all,
>
> I have Tcl8.0 for Windows. I am running Windows98. I would like to create
> a Tcl script that does the following:
>
> echo "Hello world!"
>
> I would like to be able to double click this Hello.tcl file and have a
> command prompt show me:
>
> Hello world!
>
> When I try it now, the first thing that happens is that wish tries to
> execute it. wish complains about echo not being a recognized command. I

This is correct behavior, the searching for external programs is normally
disabled in non-interactive wish80.exe. You should use puts (it's faster):

puts "Hello world!"

or this:

exec command.com /c echo "Hello world!"

or more correctly (works better on NT):

exec $env(COMSPEC) /c echo "Hello world!"

> changed the echo to a puts, and now all wish does is shows me a grey window.

The "console" output window is hidden, do this as well:

console show
puts "Hello world!"

# add a button to the grey window, called "."
button .b -text "Press to close" -command exit

> When I go into my Tclsh, and I get the % prompt, I can type `echo "Hello
> world!"` and it behaves normally. However, when I put the command into a
> file (Hello.tcl) and try to execute it from the prompt, I get an error that
> Hello.tcl does not exist.

It's probably a wierd case sensitivity issue probably, or you need to give it
a full path. What patch level of Tcl/Tk 8.0 are you using? The newer
Tcl/Tk 8.1 behaves better with Windows than 8.0.

>
> What do I need to do to run programs without using Tk (just Tcl)?

If you want to just double-click on a .tcl file and have it run
tclsh80.exe instead, you need to change the bindings in Win98 that
assign .tcl to wish80.exe. Otherwise, there is a trick you can do
to fake DOS into thinking it's a .bat file (similar to the /bin/sh
trick using comments for Unix). Use the search feature in dejanews
for this newsgroup.



> Thanks!
> Jason
>
> P.S. If you could also include an email response to jmo...@ibm.net for any
> posted replies, it would be appreciated!

You might get some replies to c.l.t. only, so check back there...

-- Scott Redman
-- Scriptics Corporation
-- The Tcl Platform Company

Bryan Oakley

unread,
May 26, 1999, 3:00:00 AM5/26/99
to
Jason Mowat <jmo...@intuitive-hs.com> wrote in message
news:3pW23.2691$eU1.3...@typhoon.mbnet.mb.ca...

> Hi all,
>
> I have Tcl8.0 for Windows. I am running Windows98. I would like to
create
> a Tcl script that does the following:
>
> echo "Hello world!"
>
> I would like to be able to double click this Hello.tcl file and have a
> command prompt show me:
>
> Hello world!
>
> When I try it now, the first thing that happens is that wish tries to
> execute it. wish complains about echo not being a recognized command.

That is correct, echo is not a standard tcl command. I think the TclX
extension defines an echo command, for what that's worth.

> I


> changed the echo to a puts, and now all wish does is shows me a grey
window.

That is to be expected. By default, when you click on a file with the suffix
.tcl (on windows), it executes wish. You confirmed this in your opening
paragraph. The output of a puts command goes to stdout for tclsh, or the
"console" in wish. By default the console is hidden, so any output from puts
won't be visible. To see the console you must explicitly request that it be
shown. Add the command "console show" to your script.

Also, when you run wish you get a window named ".", which is the gray window
you see. You might be better off writing your hello, world script like this:

label .label -text "Hello, World!"
pack .label

You'll then see the string in that default window.

> When I go into my Tclsh, and I get the % prompt, I can type `echo "Hello
> world!"` and it behaves normally.

Correct again. By default, when running interactively tclsh and wish will
try to execute a system command if you type something in that isn't
presently known to tcl. So, when you type 'echo "hello, world"', tcl doesn't
recognize it as a tcl command and therefore trys to exec a command by that
name. I think on Windows platforms there are some special cases hard-coded
in where it will actually exec command.com (or $env(COMSPEC), I guess) for
things like dir and cd.

> However, when I put the command into a
> file (Hello.tcl) and try to execute it from the prompt, I get an error
that
> Hello.tcl does not exist.

Do you really mean you get the error that "echo" doesn't exist? Again, it's
because "echo" is not a tcl command. And by default, when you click on a
script, autoexecution of system commands doesn't happen.

>
> What do I need to do to run programs without using Tk (just Tcl)?

You'll have to modify the registry entries that windows uses to know what to
run when a file with the suffix .tcl is double-clicked on. You don't have to
actually edit the registry directly -- use Explorer or the internet options
control panel or whatever (sorry -- I've done it before but I'm no windows
expert so I don't remember the precise mechanics).


Darren New

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
Scott Redman wrote:
> > What do I need to do to run programs without using Tk (just Tcl)?
>
> If you want to just double-click on a .tcl file and have it run
> tclsh80.exe instead, you need to change the bindings in Win98 that
> assign .tcl to wish80.exe. Otherwise, there is a trick you can do
> to fake DOS into thinking it's a .bat file (similar to the /bin/sh
> trick using comments for Unix). Use the search feature in dejanews
> for this newsgroup.


Actually, I would make a suggestion that the standard install defines
two extentions, .tcl and .tclsh (say), one starting Wish and one
starting Tclsh.

--
Darren New / Senior Software Architect / MessageMedia, Inc.
San Diego, CA, USA (PST). Cryptokeys on demand.
Help outlaw Dihydrogen monoxide, a major component of acid rain!

Aldric_Lhernault

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
Darren New wrote:
> Actually, I would make a suggestion that the standard install defines
> two extentions, .tcl and .tclsh (say), one starting Wish and one
> starting Tclsh.
Why not .tcl (tclsh) and .tk (wish) ?
AFAIC, that would be less confusing.

regards
Aldric

steve offutt

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
In article <3pW23.2691$eU1.3...@typhoon.mbnet.mb.ca>,
"Jason Mowat" <jmo...@intuitive-hs.com> wrote:

>
>
> What do I need to do to run programs without using Tk (just Tcl)?
>

> Thanks!
> Jason
>
> P.S. If you could also include an email response to jmo...@ibm.net
for any
> posted replies, it would be appreciated!

Jason:

As a tcl/tk "newbie" myself, I will assure you that the last thing
in the world you want to do, is limit yourself to "just Tcl". This
would limit you to running a "shell" without graphics.(a la the DOS
window command line.) After all, thats what windows is all about
(graphics) isnt it?

The people here have given you some good advice already.
These "pros" are a great help to those of us with an interest in
programming.

Steve

PS: The are no "dumb" questions.

--
Steve Offutt Industrial Mold & Tool Co
"The only person that makes no mistakes
is the one who does nothing at all"
:-)


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

Darren New

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
Aldric_Lhernault wrote:
> Why not .tcl (tclsh) and .tk (wish) ?
> AFAIC, that would be less confusing.

Mainly because that would be incompatible with what's out there now. But
yes, it would be better other than that.

Bryan Oakley

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
Darren New wrote:
>
> Aldric_Lhernault wrote:
> > Why not .tcl (tclsh) and .tk (wish) ?
> > AFAIC, that would be less confusing.
>
> Mainly because that would be incompatible with what's out there now. But
> yes, it would be better other than that.

Of course, if tk could be loaded dynamically, painlessly, and without
any extra configuration by the user, one could stick with .tcl, and for
programs that must use tk one would include "package require tk" as the
first line of the script. Double click on a .tcl file, tclsh starts up,
sees it must load tk, loads it up, and FOOM! life is good.

To me, that's the way it should be. Let the script tell the tcl shell
what packages it requires, and the shell should attempt to honor that.
What would really be cool is, if the requested package doesn't exist one
would get a dialog saying "This program requires package foo, which
isn't installed on your system. Do you want to retrieve that package
from the internet?". The pieces exist to be able to do that, but there
would have to be some sort of infrastructure in place for a script to
know where to get the package from.

--
Bryan Oakley mailto:oak...@channelpoint.com
ChannelPoint, Inc. http://purl.oclc.org/net/oakley

Cameron Laird

unread,
May 27, 1999, 3:00:00 AM5/27/99
to
In article <374DD21B...@channelpoint.com>,
Bryan Oakley <oak...@channelpoint.com> wrote:
.
.

.
>Of course, if tk could be loaded dynamically, painlessly, and without
>any extra configuration by the user, one could stick with .tcl, and for
>programs that must use tk one would include "package require tk" as the
>first line of the script. Double click on a .tcl file, tclsh starts up,
>sees it must load tk, loads it up, and FOOM! life is good.
>
>To me, that's the way it should be. Let the script tell the tcl shell
>what packages it requires, and the shell should attempt to honor that.
>What would really be cool is, if the requested package doesn't exist one
>would get a dialog saying "This program requires package foo, which
>isn't installed on your system. Do you want to retrieve that package
>from the internet?". The pieces exist to be able to do that, but there
>would have to be some sort of infrastructure in place for a script to
>know where to get the package from.
.
.
.
Indeed. At least a couple of different people
have been threatening to do this for at least
a couple of years. It's the usual, of course:
(most) all the good workers are already busy.
--

Cameron Laird http://starbase.neosoft.com/~claird/home.html
cla...@NeoSoft.com +1 281 996 8546 FAX

lvi...@cas.org

unread,
May 28, 1999, 3:00:00 AM5/28/99
to

According to Cameron Laird <cla...@Starbase.NeoSoft.COM>:
:In article <374DD21B...@channelpoint.com>,
:Bryan Oakley <oak...@channelpoint.com> wrote:
:>Of course, if tk could be loaded dynamically, painlessly, and without

:>any extra configuration by the user, one could stick with .tcl, and for

:Indeed. At least a couple of different people


:have been threatening to do this for at least
:a couple of years. It's the usual, of course:

Is there something wrong with the Plus Patch changes for this - other than,
of course, needing to use the plus patch? If not, then is it not merely
getting the changes into the default distribution - which takes enough
social and economic pressure and evangelism?
--
<URL: mailto:lvi...@cas.org> Quote: Saving the world before bedtime.
<*> O- <URL: http://www.purl.org/NET/lvirden/>
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.

Bryan Oakley

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
lvi...@cas.org wrote:
> Is there something wrong with the Plus Patch changes for this - other than,
> of course, needing to use the plus patch? If not, then is it not merely
> getting the changes into the default distribution - which takes enough
> social and economic pressure and evangelism?

BINGO! Last time I tried the plus patch it worked fabulously. As you
say, though, the problem is that it's not part of the base distribution.
Maybe it is time for the tcl community to flex some muscle and insist
that this one feature (the seemingly painless way to load tk from tclsh)
be inserted into the core for 8.1.2 or 8.2.

Perhaps _this_ would be a good test case for how the tcl community at
large can get something into the core. Though, I guess Jeffry has
already prepared the way with his marvelous string extensions.

Does this patch work on the Macintosh? I've never tried it, not having
access to a compiler on my mac.

laurent....@cgi.ca

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
lvi...@cas.org wrote:
> Is there something wrong with the Plus Patch changes for this - other than,
> of course, needing to use the plus patch? If not, then is it not merely
> getting the changes into the default distribution - which takes enough
> social and economic pressure and evangelism?

Well, there *must* be something wrong with it. A lot of people have been
clamoring for it to be included in the core distrib for years, now. Only some
parts have been included (most recently the stubs portion).

I've been using it for a long time and I only remember one problem, way back
when (something about a static{} proc that conflicted between the plus patch
and tkcvs). Otherwise, it's worked flawlessly for me. There's been discussions
about this before and I think Dr. O. had said that he didn't want to include
the "package require Tk" portion of the plus patch for one reason or another.
But don't quote me on that, since I'm too lazy to look it up in Dejanews (I'm
sick of the interface, although it seems to be the only reliable Usenent feed
around. Sheesh!).

L

P.S. How come tkcon no longer starts with tclsh+?

--
Penguin Power!

Laurent Duperval
CGI - FWFM Project
Phone: (514) 391-9523
mailto:laurent....@cgi.ca

Jan Nijtmans

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
laurent....@cgi.ca wrote:
> There's been discussions
> about this before and I think Dr. O. had said that he didn't want to include
> the "package require Tk" portion of the plus patch for one reason or another.

The reason that Tk still isn't a fully complient package is the lack of
time/resources at Scriptics. All they have to do is implement the
bugID's 1525, 2121 (which is partly a repeat for 1813) and 2074,
then Tk can be dynamically loaded on all platforms except SunOS-4.

The plus-patches provide the remaining fixes, which I will submit
as soon as at least the above 3 BugID's are handled.

--
Jan Nijtmans, CMG Arnhem B.V.
email: Jan.Ni...@wxs.nl (private)
Jan.Ni...@cmg.nl (work)
url: http://home.wxs.nl/~nijtmans/

Jan Nijtmans

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
laurent....@cgi.ca wrote:
> P.S. How come tkcon no longer starts with tclsh+?

In Tcl8.0.x it was not possible to use the command line
console in non-blocking mode. As soon as Tk was loaded
in tclsh, the console stopped working. TkCon didn't
have this problem, so that was the only way to demonstrate
the feasability of having Tk as a loadable package. Now
this problem seems to be fixed in 8.1 (I didn't test it
thorougly yet), therefore TkCon is no longer needed (Sorry,
Jeff......)

However, I'm working on a new independant package
which provides the things now removed from the
plus-patches. TkCon will be part of it, as well
as a replacement for the tcl2c utility.

Laurent Demailly

unread,
Jun 7, 1999, 3:00:00 AM6/7/99
to
I have not followed the development since tcl 8.0.3
and I don't remember the gory details I might have had to fix,
but as a data point : the tcl plugin 2.0 installer script
that I wrote does use "package require Tk 8.0"
and works fine on all unixes the plugin supported,
including SunOS 4. In the tclsh produced by the same
tcl/tk/plugin 2.0.200 source distrib (roughly equiv to 8.0.3) all
what was needed
is a package ifneeded Tk 8.0 [list load [file join $dir libtk8.0.so]]
in the lib/pkgIndex.tcl

Sorry if I completly missed the point,

Laurent

In article <374ED064...@wxs.nl>,


Jan Nijtmans <Jan.Ni...@wxs.nl> wrote:
> laurent....@cgi.ca wrote:
> > There's been discussions
> > about this before and I think Dr. O. had said that he didn't want to
include
> > the "package require Tk" portion of the plus patch for one reason or
another.
>
> The reason that Tk still isn't a fully complient package is the lack
of
> time/resources at Scriptics. All they have to do is implement the
> bugID's 1525, 2121 (which is partly a repeat for 1813) and 2074,
> then Tk can be dynamically loaded on all platforms except SunOS-4.
>
> The plus-patches provide the remaining fixes, which I will submit
> as soon as at least the above 3 BugID's are handled.
>

> --
> Jan Nijtmans, CMG Arnhem B.V.
> email: Jan.Ni...@wxs.nl (private)
> Jan.Ni...@cmg.nl (work)
> url: http://home.wxs.nl/~nijtmans/
>

--
http://www.demailly.com/~dl/


Sent via Deja.com http://www.deja.com/

Reply all
Reply to author
Forward
0 new messages