Skip to content

More effecient piping with large data #86

@codygman

Description

@codygman

Having an issue with figuring out how to use handles. Also wanted to verify handles are the correct solution rather than say runFoldLines or the other alternative I can't recall at the moment.

Surely examples of how to do the two snippets below in Shelly would be useful to many people:

zcat large.mysql.gz | mysql largedb
cat bigfile | grep things

I guess those two are pretty much the same, though I think runFoldLines might be a better alternative for the second.

{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import           Data.Monoid
import           Data.Text   as T
import           Shelly
default (T.Text)

main = shelly $ do
  -- I'm trying to do "zcat large.mysql.gz | mysql largedb" basically
  -- minimal reproduction:
  run "echo" ["a very large file"] -|- run_ "grep" ["file"] -- predictably runs out of memory
  -- runHandle "echo" ["test"] $ \h -> run "grep" ["test"] -- thought this was the equivalent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions