Hi everyone,

I want to read input from a file that contains accented characters in its
name, and Chicken says that it can't open the file. The source code is
saved in a UTF-8 encoded text file.

---------- the test code ----------

(import (chicken io))

(define read-lines-from-file
    (lambda (file-path)
        (let ([lines '()] [file-port (open-input-file file-path)])
            (set! lines (read-lines file-port))
            (close-input-port file-port)
            lines)))

(define test-lines (read-lines-from-file "c:\\temp\\íűőúöüóéá.txt"))

---------- the shell command ----------

I use Windows, and I run the script in the Command Prompt. Before running
it, I change the code page to UTF-8 with this command:

chcp 65001

Then I run it with:

csi test.scm

---------- the output ---------

CHICKEN
(c) 2008-2019, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.1.0 (rev 8e62f718)
mingw32-windows-gnu-x86 [ dload ptables ]

; loading test.scm ...
; loading c:/chicken/lib/chicken/11/chicken.io.import.so ...

Error: (open-input-file) cannot open file - No such file or directory:
"c:\\temp\\íűőúöüóéá.txt"

        Call history:

        <syntax>          [read-lines-from-file] (##core#begin (##core#set!
lines (read-lines file-port)) (close-input-port file-port) lines)
        <syntax>          [read-lines-from-file] (##core#set! lines
(read-lines file-port))
        <syntax>          [read-lines-from-file] (read-lines file-port)
        <syntax>          [read-lines-from-file] (close-input-port
file-port)
        <syntax>          [read-lines-from-file] (##core#begin lines)
        <syntax>          [read-lines-from-file] (quote ())
        <syntax>          [read-lines-from-file] (##core#quote ())
        <syntax>          [read-lines-from-file] (open-input-file file-path)
        <syntax>          (define test-lines (read-lines-from-file
"c:\\temp\\íűőúöüóéá.txt"))
        <syntax>          (##core#begin (##core#ensure-toplevel-definition
test-lines) (##core#set! test-lines (read-lines-fro...
        <syntax>          (##core#ensure-toplevel-definition test-lines)
        <syntax>          (##core#undefined)
        <syntax>          (##core#set! test-lines (read-lines-from-file
"c:\\temp\\íűőúöüóéá.txt"))
        <syntax>          (read-lines-from-file "c:\\temp\\íűőúöüóéá.txt")
        <eval>    (read-lines-from-file "c:\\temp\\íűőúöüóéá.txt")
        <eval>    [read-lines-from-file] (open-input-file file-path)    <--

If I change the file name to something that only contains ASCII characters,
then it works fine. Also, if I run the same code on a UNIX type operating
system, it works with accented characters too, only on Windows it doesn't.
What am I doing wrong?

Thanks in advance!

Reply via email to