On Mon, Mar 12, 2007 at 05:14:57PM -0500, John Goerzen wrote: > On 2007-03-06, Simon Marlow <[EMAIL PROTECTED]> wrote: > > John Goerzen wrote: > >> possible to create a pipe going directly from program A to program B. > > > > You certainly can pipe directly from one process to another: > > That only works for 2 processes. What if I have 4 processes, and want > to pipe from one to the next, all along, as in > > ls -l /tmp | tr a-zA-Z | sort | md5sum > > to give a contrived example
You can do this with runProcess, if you use System.Posix.IO.{createPipe,fdToHandle} to make a pipe and wrap the ends as handles. I hope hCreatePipe could be implemented on windows. >import System.IO >import System.Process >import System.Posix.IO >run program arguments stdin stdout = runProcess program arguments Nothing >Nothing stdin stdout Nothing >hCreatePipe = do (readFd, writeFd) <- createPipe > read <- fdToHandle readFd > write <- fdToHandle writeFd > return (read, write) >main = do (read1, write1) <- hCreatePipe > run "ls" ["-l","/tmp"] Nothing (Just write1) > (read2, write2) <- hCreatePipe > run "tr" ["a-z","A-Z"] (Just read1) (Just write2) > (read3, write3) <- hCreatePipe > run "sort" [] (Just read2) (Just write3) > (read4, write4) <- hCreatePipe > run "md5sum" [] (Just read3) (Just write4) > hash <- hGetContents read4 > putStr hash > Brandon Moore _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe