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

clear screen from within tcl

127 views
Skip to first unread message

newbee

unread,
Apr 13, 2005, 1:09:42 AM4/13/05
to
Folks,

I am very new to Tcl, just started out a couple of days infact, so pls
bear with me.

I am interested in clearing the screen from within a tcl script. Is
there a simple way to achieve this. I tried doing exec cls (I am on
win2k with ActiveTCL). I am getting this.

C:\Documents and Settings\user\Desktop>tclsh test.tcl
couldn't execute "cls": no such file or directory
while executing
"exec cls"
(file "test.tcl" line 1)

The same thing when I give from the interactive shell (tclsh) clears
the screen. Any help would be much appreciated.

Thanks.

Quokka

unread,
Apr 13, 2005, 1:51:41 AM4/13/05
to

Long answer:

cls is not a command

try auto_execok cls from interactive shell.
This will show you what cls really is!

Short answer:

eval [ auto_execok cls ]


Paul.


newbee

unread,
Apr 14, 2005, 12:37:43 AM4/14/05
to
Hi,

Thanks for the response, but I still dont quite understand, I am sorry
if this is too basic to explain, but its still the same thing. I am
getting a different error message when I do what you have given:
invalid command name "C:/WINDOWS/system32/cmd.exe"
while executing
"C:/WINDOWS/system32/cmd.exe /c cls"
("eval" body line 1)
invoked from within
"eval [ auto_execok cls ]"
(file "test.tcl" line 1)

For now I have just worked around by printing a bunch of "\n"'s to make
it look like clearing a screen.

Thanks again.

Quokka

unread,
Apr 14, 2005, 1:32:25 AM4/14/05
to
I just tried my solution from a
non-interactive shell and had exactly the same
problem. Sorry... I previously just tested
it by tying it into an interactive tclsh, where it worked.

This can be fixed by changing the command to:

eval exec [ auto_execok cls ]

HOWEVER, although this does run the command...
it does not clear the screen... Ask
Mr Gates why.

And I don't know how you can work around that.

If it was my problem I would use tk and avoid the
whole issue.


Regards

Paul

Arjen Markus

unread,
Apr 14, 2005, 3:14:10 AM4/14/05
to

The reason it worked from an interactive shell and
not from a script is that an interactive shell will
try to run unknown Tcl commands or procedures as
external programs (via an implicit exec).

This is generally undesirable for a script - suppose
you intended to define a procedure "rm" or "del" and
forgot it - that would possibly destroy a file or two :)

The command cls simply seems to print ASCII character 12
(new page or something). I have no clue as to why that
does not clear the screen. Under UNIX the sequence
"\x1b[2J" does clear the screen.

Regards,

Arjen

Khaled

unread,
Apr 14, 2005, 10:10:24 AM4/14/05
to
Quokka wrote:
>
> HOWEVER, although this does run the command...
> it does not clear the screen... Ask
> Mr Gates why.
>

On an interactive windows shell:
%
% auto_execok cls
C:/WINNT/system32/CMD.EXE /c cls
%
% eval [auto_execok cls] ;# This clears the screen
%
% eval exec [auto_execok cls]; This does not

%
% cmd.exe /c cls ;# This clears the screen
% eval cmd.exe /c cls ;# Works as well. Just to test [eval]
%
% exec cmd.exe /c cls ;# This Does not

%

Does not that suggest that [exec] is the cluprit? May be (this time) Mr
Gates is not the one to blame.

Rgrds,
Khaled

Bruce Hartweg

unread,
Apr 14, 2005, 11:37:18 AM4/14/05
to

Khaled wrote:

except that in an interactive case, the unknowon proc just
adds the exec for you.

But looking at it there have been a few different flavors of doing
that ans it seems that at one time it never did redirects, at
others it alwasy added >&@stdout <@stdin and the latest code
seems to add that conditionally, so maybe all tyhat needs to be done
in you explicit exec case is to add the redirects otherwise the
the cls is clearing a non-existent screen.

Bruce

Khaled

unread,
Apr 14, 2005, 12:55:03 PM4/14/05
to
Bruce Hartweg wrote:
>
> But looking at it there have been a few different flavors of doing
> that ans it seems that at one time it never did redirects, at
> others it alwasy added >&@stdout <@stdin and the latest code
> seems to add that conditionally, so maybe all tyhat needs to be done
> in you explicit exec case is to add the redirects otherwise the
> the cls is clearing a non-existent screen.
>
> Bruce

Just to clarify the workaround of Bruce,
instead of: eval exec [auto_execok cls], use:

eval exec >&@stdout <@stdin [auto_execok cls]

Rgrds,
Khaled

newbee

unread,
Apr 15, 2005, 1:48:48 AM4/15/05
to
Its just a simple console app that I was trying to work with and needed
a clear screen functionality. Thanks everyone for your responses, the
last one works like a charm, just what I was looking for :) Guess the
language is worth exploring after all, atleast as long as it has such a
fantastic peer group.

0 new messages