System.Process.readProcess "yes" [] "" >>= return . take 100

I would expect the expression above to finish - but it doesn't. Is this a bug?

No, that's not a bug. From the documentation on «readProcess»:
readProcess forks an external process, reads its standard output strictly, blocking until the process terminates, and returns the output string.
Since «yes» never terminates, the call to «readProcess» will block forever. Lukas

Hi, On 2014-09-02 03:07, David Fox wrote:
I would expect the expression above to finish - but it doesn't. Is this a bug?
Below is a lazier variant of readProcess. If you use this, your example will work as expected. You can also pipe several processes together, e.g. readProcess (shell "yes") "" >>= readProcess (shell "head") -- Thomas H -- | Lazy variant of readProcess module Process(readProcess,shell,proc) where import System.Process hiding (readProcess) import System.IO(hGetContents,hClose,hPutStr) import Control.Concurrent(forkIO) import System.IO.Error(tryIOError) -- | Feed some input to a shell process and read the output lazily readProcess :: CreateProcess -- ^ Process specified with 'shell' or 'proc' -> String -- ^ input to the process -> IO String -- ^ output from the process readProcess proc input = do (Just stdin,Just stdout,Nothing,ph) <- createProcess proc{std_in=CreatePipe,std_out=CreatePipe} forkIO $ do tryIOError $ hPutStr stdin input tryIOError $ hClose stdin waitForProcess ph return () hGetContents stdout
participants (3)
-
David Fox
-
Lukas Braun
-
Thomas Hallgren