[Haskell-cafe] Re: Writing an 'expect'-like program with runInteractiveCommand

ChrisK haskell at list.mightyreason.com
Thu May 1 18:29:31 EDT 2008


Are you adjusting 'System.IO.hSetBuffering' to NoBuffering for those handles?


Graham Fawcett wrote:
> Hi folks,
> 
> I would like to communicate with an external, line-oriented process,
> which takes a sequence of one-line commands, each returning an
> arbitrary number of lines, and waits for another command after each
> response.  So, something like:
> 
> sendCmd :: (Handle, Handle) -> String -> IO [String]
> ...
> 
> main = do
>   handles <- connectToExternalProcess
>   sendCmd handles "do something"
>   resp <- sendCmd "get results" -- needs strict I/O, before "quit"?
>   sendCmd "quit"
>   mapM_ putStrLn resp
> 
> I've tried using runInteractiveCommand, and several combinations of
> hFlush, hWaitForInput, etc., but I can't find a combination that
> actually works.
> 
> I know this is a sketchy description, but can anyone offer some sample
> code, or point me toward a program that has similar behaviour?
> 
> Thanks,
> Graham



More information about the Haskell-Cafe mailing list