[Haskell-cafe] "piping" to system call

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Sep 23 11:49:15 EDT 2008

On 2008 Sep 23, at 7:55, Marc Weber wrote:

> On Tue, Sep 23, 2008 at 01:37:56PM +0200, Janis Voigtlaender wrote:
>> 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/ 
> :runInteractiveProcess
>        rnuInteractiveCommand does would you want
>        (in,out,err,pId) <- runInteractiveProcess "cat" ...
>        hPutStrLn "test" in
>        hClose in
>        outContents <- hGetContents out
>        print outContents

Note that this will deadlock if either the input or the output is too  
long; you should forkIO a thread to do either the input or the output.

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list