Opened 12 years ago

Closed 12 years ago

Last modified 45 years ago

#139 closed bug (None)

readFile problems

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: None Version: None
Keywords: Cc:
Operating System: Architecture:
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Hello,

We are two students from the University of Utrecht (the 
Netherlands) working on a project in Haskell. During 
work on the project, we encountered a problem with 
the 'readFile' IO Monad.  readFile stops reading a file 
when it encounters ASCII character 26 (\SUB or \^Z - the 
escape character), as the following piece of coding 
shows. We've tested this with both the Hugs interpreter 
and the GHC compiler, but both encounter the same 
problem. Are there any known solutions for this?

Regards,
Richard Nieuwenhuis and Niels Reyngoud
[email protected], [email protected]


------------

module Main where

main = do let output = problemtext
     putStr output
     putStr "\n\n"
     writeFile "outputfile.txt" output
         text <- readFile "outputfile.txt"
     putStr text


problemtext :: String
problemtext = "strange\SUBstrange"


Change History (1)

comment:1 Changed 12 years ago by simonmar

  • Status changed from assigned to closed
Logged In: YES 
user_id=48280

On Windows, the ^Z character is interpreted as end-of-file.  
To subvert this behaviour, you can put the file into Binary 
mode using GHC.Handle.hSetBinaryMode. (unfortunately this 
function isn't available form anywhere more stable, yet).
Note: See TracTickets for help on using tickets.