convert processTranscript to use hGetLineUntilExitOrEOF
It does use it on both stdout and stderr. It seems unlikely the problem could really affect stdout, but the unix implementation of it combines both into a single handle in any case.
This commit is contained in:
parent
ff0927bde9
commit
b13c44cccc
1 changed files with 9 additions and 8 deletions
|
@ -15,7 +15,6 @@ module Utility.Process.Transcript (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Utility.Process
|
import Utility.Process
|
||||||
import Utility.Misc
|
|
||||||
|
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Exit
|
import System.Exit
|
||||||
|
@ -63,10 +62,10 @@ processTranscript'' cp input = do
|
||||||
, std_err = UseHandle writeh
|
, std_err = UseHandle writeh
|
||||||
}
|
}
|
||||||
withCreateProcess cp' $ \hin hout herr pid -> do
|
withCreateProcess cp' $ \hin hout herr pid -> do
|
||||||
get <- asyncreader readh
|
get <- asyncreader pid readh
|
||||||
writeinput input (hin, hout, herr, pid)
|
writeinput input (hin, hout, herr, pid)
|
||||||
transcript <- wait get
|
|
||||||
code <- waitForProcess pid
|
code <- waitForProcess pid
|
||||||
|
transcript <- wait get
|
||||||
return (transcript, code)
|
return (transcript, code)
|
||||||
#else
|
#else
|
||||||
{- This implementation for Windows puts stderr after stdout. -}
|
{- This implementation for Windows puts stderr after stdout. -}
|
||||||
|
@ -77,16 +76,18 @@ processTranscript'' cp input = do
|
||||||
}
|
}
|
||||||
withCreateProcess cp' $ \hin hout herr pid -> do
|
withCreateProcess cp' $ \hin hout herr pid -> do
|
||||||
let p = (hin, hout, herr, pid)
|
let p = (hin, hout, herr, pid)
|
||||||
getout <- asyncreader (stdoutHandle p)
|
getout <- asyncreader pid (stdoutHandle p)
|
||||||
geterr <- asyncreader (stderrHandle p)
|
geterr <- asyncreader pid (stderrHandle p)
|
||||||
writeinput input p
|
writeinput input p
|
||||||
transcript <- (++) <$> wait getout <*> wait geterr
|
|
||||||
code <- waitForProcess pid
|
code <- waitForProcess pid
|
||||||
|
transcript <- (++) <$> wait getout <*> wait geterr
|
||||||
return (transcript, code)
|
return (transcript, code)
|
||||||
#endif
|
#endif
|
||||||
where
|
where
|
||||||
asyncreader = async . hGetContentsStrict
|
asyncreader pid h = async $ reader pid h []
|
||||||
|
reader pid h c = hGetLineUntilExitOrEOF pid h >>= \case
|
||||||
|
Nothing -> return (concat (reverse c))
|
||||||
|
Just l -> reader pid h (l:c)
|
||||||
writeinput (Just s) p = do
|
writeinput (Just s) p = do
|
||||||
let inh = stdinHandle p
|
let inh = stdinHandle p
|
||||||
unless (null s) $ do
|
unless (null s) $ do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue