I’ve gotten this error from Tcl flush command:
error flushing "stdout": I/O error
Any ideas why it can happen? Also, the man page doesn’t say anything about flush returning errors. Can the same error come from puts?
And ultimately: what do do about it?
Thank you.
By default Tcl uses line buffering on
stdout(more on this later). This means whatever youputsthere gets buffered and is only output when the newline is seen in the buffer or when youflushthe channel. So, yes, you can get the same error fromputsdirectly, if a call to it is done on an unbuffered channel or if it managed to hit that “buffer full” condition so that the underlying medium is really accessed.As to “I/O error”, we do really need more details. Supposedly the
stdoutof your program has been redirected (or reopened), and the underlying media is inaccessible for some reason.You could try to infer more details about the cause by inspecting the
POSIXerrnoof the actual failing syscall — it’s accessible via the globalerrorCodevariable after a Tcl command involving such a syscall signalized error condition. So you could go like this:(since Tcl 8.5 you can directly ask
catchto return all the relevant info instead of inspecting magic variables, see the manual).Providing more details on how you run your program or whether you reopen
stdoutis strongly suggested.A note on buffering. Output buffering can be controlled using
fconfigure(orchan configuresince 8.5 onwards) on a channel by manipulating its-bufferingoption. Usually it’s set tolineonstdoutbut it can be set tofullornone. When set tofull, the-buffersizeoption can be used to control the buffer size explicitly.