Skip to content

Instantly share code, notes, and snippets.

@gdoteof
Created May 9, 2014 23:21
Show Gist options
  • Save gdoteof/24b17f55de10f8b5a1b9 to your computer and use it in GitHub Desktop.
Save gdoteof/24b17f55de10f8b5a1b9 to your computer and use it in GitHub Desktop.
input max size bug
import Prelude
import System.IO
import System.Process
import Control.Applicative
import Control.Monad.IO.Class
import Data.Monoid
import System.Environment
main :: IO ()
main = do
args <- getArgs
fromFile <- drainFifo $ head args
print fromFile
-- we use drainFifo instead of a normal readFile because Haskell's non-blocking IO treats FIFOs wrong
drainFifo :: FilePath -> IO String
drainFifo f = do
(i, out, e, p) <- runInteractiveProcess "bash" ["-c", "exec cat<" <> f] Nothing (Just [])
hClose i
hClose e
hSetBinaryMode out False
contents <- hGetContents out <* waitForProcess p
return contents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment