[Haskell-cafe] "piping" to system call

Jules Bean jules at jellybean.co.uk
Tue Sep 23 09:38:04 EDT 2008

Janis Voigtlaender wrote:
> Jules Bean wrote:
>> Marc Weber wrote:
>>> On Tue, Sep 23, 2008 at 01:37:56PM +0200, Janis Voigtlaender wrote:
>>>>  Hi,
>>>>  assume I have a program taking input from stdin. How do I call it from
>>>>  Haskell while feeding to it a string as input.
>>> Sure, have a look at 
>>> http://hackage.haskell.org/packages/archive/process/ 
>>>         rnuInteractiveCommand does would you want
>>>         (in,out,err,pId) <- runInteractiveProcess "cat" ...
>>>         hPutStrLn "test" in
>>>         hClose in
>>>         outContents <- hGetContents out
>>>         print outContents
>> Beware. The above code is broken.
>> Whether it appears to work depends on your OS, buffering settings, and 
>> the size of any underlying buffers.
> Thanks for the warning. I needed it only for a small scripting task, and
> it seems to work well enough. Actually, I am not even interested in the
> output, so I just went for waitForProcess. This comes with additional
> warnings in the docs, but I did not experience any problems in my
> concrete setting so far.

If you don't care about the output, it's fine if you send the output to 

The deadlock is when you try to read the output and send the input from 
the same thread.

However if the output is to "out" and you never read it then that *will* 
deadlock, but probably only when some OS buffer gets full (e.g. after 8k 
of output)


More information about the Haskell-Cafe mailing list