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

  1. package require Tcl 9
  2. set fd [open "data.txt" w+]
  3. fconfigure $fd -encoding binary
  4. puts $fd AB\xc0\x40CD\nEFG
  5. close $fd
  6.  
  7. set fd [open "data.txt"]
  8. fconfigure $fd -encoding utf-8 -strictencoding 1
  9. # That next line will hand indefinitely
  10. set data [gets $fd]
  11. puts "not reached"
  12. puts [tell $fd]
  13. close $fd
  14. puts $data
  15.  
  16.