user2720323
user2720323

Reputation: 287

TCL : Usage of 'flush' command

flush channelId

How can we know the the channel is blocked?

And can anyone explain when can we use the flush command in TCL?

Upvotes: 0

Views: 7889

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137717

The flush command directs Tcl to ensure all its buffered output for a channel is written to the underlying operating system immediately. You hardly ever need to use flush explicitly; the main exception is when you are prompting the user for input without using a new line:

puts -nonewline "Please enter your name: "
flush stdout
set name [gets stdin]

However, if you are having problems with flushing for other reasons, you actually need to use fconfigure to change the default output buffer management strategy:

# Turn off output buffering
fconfigure $channel -buffering none

Every channel supports three buffering strategies:

  • none — no buffering at all.
  • full — buffer until a full output buffer is built up (the output buffer size is controllable but you hardly ever need to touch it) and then write that whole buffer at once.
  • line — buffer until a full line of output can be written at once.

Most channels default to full as that gives the best performance when writing bulk data, but the stdout channel defaults to line when writing to a terminal, and the stderr channel always defaults to none (as it is used for writing messages when the system is very poorly and might crash, among other things).

Upvotes: 4

Related Questions