Saturday, March 04, 2006

 

Perl-alike "open2" in Haskell

import System.Posix
import IO

-- similar to Perl open2
open2 :: String -> [String] -> IO (Fd,Fd)
open2 fileName cmdArgs = do
          (to_out,to_in) <- createPipe
          (from_out,from_in) <- createPipe
          pid <- forkProcess (do
              dupTo to_out stdInput
              dupTo from_in stdOutput
              closeFd to_in
              closeFd from_out
              closeFd to_out
              closeFd from_in
              executeFile fileName True cmdArgs Nothing)
          closeFd to_out
          closeFd from_in
          return (to_in,from_out)

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?