[Haskell-cafe] Fwd: Default stdout buffering of child process of createProcess
Chris Myzie
cmyzie28 at gmail.com
Sat Aug 2 03:07:25 UTC 2014
I'm reposting this message because I think it only went to the google group
and not the official haskell-cafe list:
On Friday, August 1, 2014 10:06:32 AM UTC-4, Chris Myzie wrote:
>
> As a workaround, I am able to trick the child haskell process into
> thinking it's running in an interactive terminal by wrapping it with
> /usr/bin/script:
>
> createProcess (proc "/usr/bin/script" ["-qc","./A","/dev/null"]) { std_out
> = CreatePipe }
>
> I still think haskell is using screwy defaults for stdout buffering..
>
> On Thursday, July 31, 2014 3:24:47 PM UTC-4, Chris Myzie wrote:
>>
>> Hello,
>>
>> I'm trying to write a wrapper process that will be able to read any child
>> process' stdout. The problem I'm running into is that unless I force the
>> child's stdout to LineBuffering, it defaults to BlockBuffering. Is
>> BlockBuffering really the default in this case? I don't want to have to
>> modify all of the child processes that I want to use with this wrapper.
>>
>> Below is a simple test case. A.hs is the child process, and B.hs is the
>> wrapper. If I run B.hs, I will get no output unless I uncomment the line
>> in A.hs.
>>
>> Thanks,
>> Chris
>>
>>
>> ------------------------------ A.hs ---------------------------
>> import Control.Concurrent
>> import System.IO
>>
>> main :: IO ()
>> main = do
>> -- hSetBuffering stdout LineBuffering
>> putStrLn "test" >> threadDelay 1000000 >> main
>>
>>
>> ------------------------------ B.hs ---------------------------
>> import Control.Monad
>> import System.IO
>> import System.Process
>>
>> main :: IO ()
>> main = do
>> (_,Just h,_,_) <- createProcess (proc "./A" []) { std_out = CreatePipe }
>> hSetBuffering h LineBuffering
>> forever $ hGetLine h >>= putStrLn
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140801/ffea6298/attachment.html>
More information about the Haskell-Cafe
mailing list