I'm trying to set up a "bridge" between my Haskell code and an interactive command-line process. More specifically, I'm trying to run an Elm REPL and send/receive through stdin/stdout. I wasn't sure exactly which library to use for this, but I went with typed-process.
The issue I have is that my Haskell program finishes (or quits) while the REPL process is still running. How do I avoid this?
Also, another problem is that the REPL process isn't getting any input from the stdin handle.
My current code looks like this:
run :: Document -> IO (Result () Text)
run (Document moduleName tests) = do
let config = createConfig
p <- startProcess config
hSetBuffering (getStdin p) NoBuffering
hSetBuffering (getStdout p) NoBuffering
Data.Text.IO.hPutStr (getStdin p) "True\n"
Data.Text.IO.hGetChunk (getStdout p) >>= print
_ <- waitExitCode p
return (Ok ())
{-| Config for process.
-}
createConfig =
shell "elm repl"
|> setStdin createPipe
|> setStdout createPipe
|> setStderr closed