hClose: invalid argument (Invalid or incomplete multibyte or wide character)

I have this program main = writeFile "check.out" "ü" that's u-umlaut, and the source file is utf-8-encoded and ghc-6.12.3 compiles it without problems but when running, I get hClose: invalid argument (Invalid or incomplete multibyte or wide character) (debian 5.0.6, kernel 2.6.18-6-686. I know that's somewhat dated. Would upgrading help?) Regards - J.W.

On Tuesday 05 October 2010 23:34:56, Johannes Waldmann wrote:
I have this program
main = writeFile "check.out" "�"
that's u-umlaut, and the source file is utf-8-encoded and ghc-6.12.3 compiles it without problems but when running, I get
hClose: invalid argument (Invalid or incomplete multibyte or wide character)
(debian 5.0.6, kernel 2.6.18-6-686. I know that's somewhat dated. Would upgrading help?)
Regards - J.W.
What does locale say your locale is? If it's *.UTF-8, it should work, if not, that's a likely cause.

What does locale say your locale is? If it's *.UTF-8, it should work, if not, that's a likely cause.
So, it was indeed C. I switched this - what now? Recompile? Just my application? All of ghc? ...

On Wednesday 06 October 2010 00:30:31, Johannes Waldmann wrote:
What does locale say your locale is? If it's *.UTF-8, it should work, if not, that's a likely cause.
So, it was indeed C. I switched this - what now? Recompile? Just my application? All of ghc? ...
I think that would be overkill. As far as I know, it should now work without recompiling. Try your example first.

My application was actually running as a CGI program and I needed some time to find out that I should put: SetEnv LC_ALL en_US.UTF-8 into /etc/apache2/sites-available/default

Hi, Daniel Fischer wrote:
On Tuesday 05 October 2010 23:34:56, Johannes Waldmann wrote:
main = writeFile "check.out" "ü"
that's u-umlaut, and the source file is utf-8-encoded and ghc-6.12.3 compiles it without problems but when running, I get
hClose: invalid argument (Invalid or incomplete multibyte or wide character)
In order to make the behaviour independent of the locale (which is desirable for programs storing state in text files), you can use functions like writeFileUTF8 and readFileUTF8 here: import System.IO writeFileUTF8 file text = withFile file WriteMode $ \handle -> do hSetEncoding handle utf8 hPutStr handle text readFileUTF8 file = do handle <- openFile file ReadMode hSetEncoding handle utf8 hGetContents handle main = do let s = "äöü" writeFileUTF8 "test.out" s s' <- readFileUTF8 "test.out" putStrLn $ unwords [s, "==", s'] Of course using System.IO.UTF8 from utf8-string would also work. HTH, Bertram
participants (3)
-
Bertram Felgenhauer
-
Daniel Fischer
-
Johannes Waldmann