Posted to tcl by de at Wed Dec 21 13:39:34 GMT 2022view pretty

package require Tcl 9
set fd [open "data.txt" w+]
fconfigure $fd -encoding binary
puts $fd AB\xc0\x40CD\nEFG
close $fd

set fd [open "data.txt"]
fconfigure $fd -encoding utf-8 -strictencoding 1
# That next line will hand indefinitely
set data [gets $fd]
puts "not reached"
puts [tell $fd]
close $fd
puts $data