[Haskell-cafe] making the GHC Api not write to stderr

Phyx lonetiger at gmail.com
Thu May 20 16:07:36 EDT 2010


I've thought about that, but my specific problem is that I'm calling the
Haskell code compiled to a shared lib and then hPutStr is failing,
presumable because there is no valid stderr (and I would image also no stdin
or out).

So in order for me to use that method I would have to create a new file
handle and direct stderr to that. Or somehow create a fake Handle and pass
it that.

 

Or another alternative is on the side where I call the lib, create and
attach some hidden console to the process and have it write there.

 

But that all seems like a hackish way out, It would be best if  the API just
allowed me to turn off this behavior of writing to stderr.

 

From: Jean-Denis Koeck [mailto:jdkoeck at gmail.com] 
Sent: Thursday, May 20, 2010 21:59
To: Phyx
Subject: Re: [Haskell-cafe] making the GHC Api not write to stderr

 

Maybe this
<http://nominolo.blogspot.com/2010/04/haskell-tip-redirect-stdout-in-haskell
.html>  could help you ?

2010/5/20 Phyx <lonetiger at gmail.com>

I was wondering how to forcibly quiet down the API. I have a custom handler
in place, but when I call the function on failure both my handler gets
called and somewhere somehow errors get printed to the stderr, which I
really need to avoid.

 

My current code looks like

 

getModInfo :: Bool -> String -> String -> IO (ApiResults ModuleInfo)

getModInfo qual file path = handleSourceError processErrors $

runGhc (Just libdir) $ do

    dflags <- getSessionDynFlags

    setSessionDynFlags $ configureDynFlags dflags

    target <- guessTarget file Nothing

    addTarget target

    setSessionDynFlags $ dflags { importPaths = [path] }

    load LoadAllTargets    

    graph <- depanal [] False

    let modifier = moduleName . ms_mod

        modName  = modifier $ head graph

        includes = includePaths dflags

        imports  = importPaths dflags

        

    dflags' <- Debug.trace (moduleNameString modName) getSessionDynFlags

    setSessionDynFlags $ dflags' { includePaths = path:includes

                                 , importPaths  = path:imports

                                 }

 

    parsed  <- parse modName

    checked <- typecheckModule parsed


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100520/afff8f61/attachment.html


More information about the Haskell-Cafe mailing list