How to keep commands quiet in TCL?

What you're observing is just the standard behaviour of an interactive Tcl shell: each Tcl command returns a result value, and a return code. If the Tcl shell is interactive (that is, its input and output streams are connected to a terminal), after executing each command, the string representation of the result value the command returned is printed, and then the prompt is shown again. If the shell is not interactive, no results are printed and no prompt is shown.

(On a side note, such behaviour is ubiquitous with interpreters — various Unix shells, Python and Ruby interpreters do the same thing.)

If you want to inhibit such printouts in an interactive session (comes in handy from time to time), a simple hack to achieve that is to chain the command you want to "silence" with a "silent" command (producing a value whose string representation is an empty string), for instance:

set a [open "giri.txt" r]; list

Here, the list returned by the list command having no arguments is an empty list whose string representation is an empty string. In an interactive shell, this chain of commands will output literally nothing.

It bears repeating that such a hack might only ever be needed in an interactive session — do not use it in scripts.


You can turn this off in an interactive tclsh

set tcl_interactive false

but that will also turn off the prompt.


In Mentor ModelSim Tcl it is possible to do:

quietly set answer 42

Also in Mentor Questa:

help quietly

The quietly command turns off transcript echoing for the specified command.

Tags:

Tcl