• Tcl 9: Issue reading file in utf-8

    From meshparts@[email protected] to comp.lang.tcl on Tue Sep 2 00:58:23 2025
    From Newsgroup: comp.lang.tcl

    I have issues with Tcl 9 reading a text file using:

    set fid [open Profile.csv r]
    set content [read $fid]
    close $fid

    I get following error:

    error reading "file5b852c0": invalid or incomplete multibyte or wide
    character

    Tcl 8 works.

    I also tried reading the file line-by-line

    while {[gets $fid line] >= 0} {
    puts $line
    }

    but the error occures at first line.

    I could not attach the file, Thunderbird complains about "non-binary distribution".

    But I think the issue is the first char in this file, which might not be utf-8, not sure though.

    On the other side, Tcl 8 could read the file.
    I wonder if Tcl just got unrobust with version 9.

    Regards
    Alexandru





    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@[email protected] to comp.lang.tcl on Tue Sep 2 01:06:07 2025
    From Newsgroup: comp.lang.tcl

    Am 02.09.2025 um 00:58 schrieb meshparts:
    I have issues with Tcl 9 reading a text file using:

    set fid [open Profile.csv r]
    set content [read $fid]
    close $fid

    I get following error:

    error reading "file5b852c0": invalid or incomplete multibyte or wide character

    Tcl 8 works.

    I also tried reading the file line-by-line

    while {[gets $fid line] >= 0} {
      puts $line
    }

    but the error occures at first line.

    I could not attach the file, Thunderbird complains about "non-binary distribution".

    But I think the issue is the first char in this file, which might not be utf-8, not sure though.

    On the other side, Tcl 8 could read the file.
    I wonder if Tcl just got unrobust with version 9.

    Regards
    Alexandru





    The issue is that the file is encoded in cp1252 instead utf-8.
    I don't understand how this can lead to an error.
    I expect wrong chars in the return value, but no error.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From et99@[email protected] to comp.lang.tcl on Mon Sep 1 18:04:07 2025
    From Newsgroup: comp.lang.tcl

    On 9/1/2025 4:06 PM, meshparts wrote:

    The issue is that the file is encoded in cp1252 instead utf-8.
    I don't understand how this can lead to an error.
    I expect wrong chars in the return value, but no error.


    check out the incompatibility section : https://www.tcl-lang.org/software/tcltk/9.0.html

    note in particular: I/O malencoding default response: raise error (-profile strict)
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@[email protected] to comp.lang.tcl on Tue Sep 2 04:03:30 2025
    From Newsgroup: comp.lang.tcl

    Am 02.09.2025 um 03:04 schrieb et99:
    profile strict
    Thank you for the hint.
    I'll add -profile tcl8 to my fconfigure commands.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@[email protected] to comp.lang.tcl on Tue Sep 2 08:03:02 2025
    From Newsgroup: comp.lang.tcl

    Am 02.09.2025 um 04:03 schrieb meshparts:
    Am 02.09.2025 um 03:04 schrieb et99:
    profile strict
    Thank you for the hint.
    I'll add -profile tcl8 to my fconfigure commands.

    It is more constructive to add a "fconfigure -encoding".
    This is also the case for 8.6.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@[email protected] to comp.lang.tcl on Tue Sep 2 09:13:27 2025
    From Newsgroup: comp.lang.tcl

    Am 02.09.2025 um 08:03 schrieb Harald Oehlmann:
    Am 02.09.2025 um 04:03 schrieb meshparts:
    Am 02.09.2025 um 03:04 schrieb et99:
    profile strict
    Thank you for the hint.
    I'll add -profile tcl8 to my fconfigure commands.

    It is more constructive to add a "fconfigure -encoding".
    This is also the case for 8.6.
    Of course, I do this anyway.
    The issue is that I do "fconfigure -ecoding ut-8" by default but the
    file is cp1252.
    Now I have to do "fconfigure -ecoding ut-8 -profile tcl8" which I
    assumed that it work, since it's not documented (see Ashok's Tcl/Tk
    online documentation).
    This seems to work as I get no error after this change.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@[email protected] to comp.lang.tcl on Tue Sep 2 13:46:43 2025
    From Newsgroup: comp.lang.tcl

    Am 02.09.2025 um 09:13 schrieb meshparts:
    Am 02.09.2025 um 08:03 schrieb Harald Oehlmann:
    Am 02.09.2025 um 04:03 schrieb meshparts:
    Am 02.09.2025 um 03:04 schrieb et99:
    profile strict
    Thank you for the hint.
    I'll add -profile tcl8 to my fconfigure commands.

    It is more constructive to add a "fconfigure -encoding".
    This is also the case for 8.6.
    Of course, I do this anyway.
    The issue is that I do "fconfigure -ecoding ut-8" by default but the
    file is cp1252.
    Now I have to do "fconfigure -ecoding ut-8 -profile tcl8" which I
    assumed that it work, since it's not documented (see Ashok's Tcl/Tk
    online documentation).
    This seems to work as I get no error after this change.

    It does the following: interpret any non utf8-correct sequences as
    iso-8859-1. If this is what you want, go for it. I don't see any data
    which may comply to this use-case...

    For me, the TCL8 behaviour of replacing by 8859-1 or "?" without raising
    an error was always very interesting...

    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2