[Haskell-cafe] catting to cat gets stuck at > 135K

Jason Dusek jason.dusek at gmail.com
Mon Nov 10 16:29:36 EST 2008

  I've put together a simple test case for a rather annoying
  problem. I've got a program that drives other programs. For
  example, it can drive `cat`:

 :; Simple cat a-file

  When the file is a little bit greater than 135060 bytes, this
  program fails to produce any output at all -- I need to use ^C
  to get my console back.

  I have a similar program that encounters the same issue a
  little after 139192 bytes. The inconsistency is one baffling
  feature of this bug.

  If I remove the `hClose`, the example program just hangs, no
  matter the size of the input.

  It is entirely possible that I have overlooked some subtle
  feature of pipe semantics -- indeed, I hope that is the case.


import Data.ByteString.Lazy
import System.Process
import System.Environment
import System.IO (hClose)
import Prelude hiding (writeFile, readFile)

main                         =  do
  exe:file:_                <-  getArgs
  bytes                     <-  readFile file
  foo                       <-  simple exe bytes []
  writeFile (file ++ ".foo") foo

 -- Manufactures a simple stream handler from a command line utility.
 :: String -> ByteString -> [String] -> IO ByteString
simple exe bytes args        =  do
    (i, o, e, p)            <-  runInteractiveProcess exe args Nothing Nothing
    hPut i bytes
    s                       <-  hGetContents o
    hClose i
    return s

More information about the Haskell-Cafe mailing list