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.
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.
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.
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
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
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
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
Just to clarify the workaround of Bruce,
instead of: eval exec [auto_execok cls], use:
eval exec >&@stdout <@stdin [auto_execok cls]
Rgrds,
Khaled