Hi,
I tried your version of exec. Still the same problem. With 2.10 it
outputs "aaa" (as expected) and doesn't terminate (???), with 3.03
(-fno-specialise) it gives
^@^@^@ and terminates.
I guess it is some control character...And yes, this is Solaris. I
would bet that this has something to do with the new IOMonad. Any
other guess?
Thanks, Laszlo
PS. I include the source I am using so we both now what I am talking
about.
---
module Main(main) where
import IO
import Posix
import System
main = do
a <- echoIt "aaa"
putStrLn a
where
-- aaa = "aaa" : aaa
echoIt x = do
(inH, outH) <- exec "/bin/cat" []
hPutStr inH x
-- fd <- handleToFd inH
-- fdClose fd
hClose inH
x <- hGetContents outH
return x
-- sof says this works...
exec :: String -> [String] -> IO (Handle, Handle)
exec cmd args = do
(cReadFd, pWriteFd) <- createPipe
(pReadFd, cWriteFd) <- createPipe
child <- forkProcess
case child of
Just x -> do -- parent
fdClose cReadFd
fdClose cWriteFd
pWriteH <- fdToHandle pWriteFd
pReadH <- fdToHandle pReadFd
hSetBuffering pWriteH NoBuffering
hSetBuffering pReadH NoBuffering
return (pWriteH, pReadH)
Nothing -> do -- child
-- replace stdin, stdout with read and write end of the pipe.
dupTo cReadFd stdInput
dupTo cWriteFd stdOutput
fdClose pReadFd
fdClose pWriteFd
executeFile cmd True args Nothing
fdClose cReadFd
fdClose cWriteFd
exitWith ExitSuccess
{- Old version
exec :: String -> [String] -> IO (Handle, Handle)
exec cmd args = do
(pWriteFd, cReadFd) <- createPipe
(cWriteFd, pReadFd) <- createPipe
child <- forkProcess
case child of
Just x -> do -- parent
pWriteH <- fdToHandle pWriteFd
pReadH <- fdToHandle pReadFd
fdClose cReadFd
fdClose cWriteFd
hSetBuffering pWriteH NoBuffering
hSetBuffering pReadH NoBuffering
return (pWriteH, pReadH)
Nothing -> do -- child
-- replace stdin, stdout with read and write end of the pipe.
dupTo cReadFd stdInput
dupTo cWriteFd stdOutput
fdClose pReadFd
fdClose pWriteFd
executeFile cmd True args Nothing
exitWith ExitSuccess
-}