haskellghc

How to output or redirect GHC compile errors to a file instead of standard output?


I'm trying to compile a haskell file that has a HUGE number of errors in it. I want to start debugging the first one but unfortunately there are so many that they go off the screen.

I want to pipe the error messages to a file so that I can read from the top, but normal methods don't seem to work.

I've tried:

ghc File.hs > errors.log
ghc File.hs >> errors.log
ghc File.hs | more

None of them work. Using > and >> only writes the first couple of lines to the file and then the rest to standard output. Using more, less, cat etc doesn't make any difference at all.

Is there a flag for GHC that will let me output to a file?

(I should probably let you know that I'm working on a Windows machine with Cygwin.)


Solution

  • Most programs write output to the standard output (file descriptor 1) and error messages to the standard error (file descriptor 2).

    You can ask your shell to redirect the standard error to another location like this:

    ghc File.hs > output.log 2> errors.log
    

    or if you want them in the same file:

    ghc File.hs > output.log 2>&1
    

    See your shell's manpage section of redirections for full details. Note that the shells are picky about the order of the redirections.